Can anyone explain why the input size doesn't match the length of the string it displays? And how I can fix this?
<table>
<tr>
<td>utf length<?php echo mb_strlen('hello', 'UTF-8'); ?>
<input type="text" name="input" readonly value="hello" size="<?php echo mb_strlen('hello', 'UTF-8'); ?>">
</td>
</tr>
<tr>
<td>non utf lenth<?php echo strlen('hello'); ?>
<input type="text" name="input" readonly value="hello" size="<?php echo strlen('hello'); ?>">
</td>
</tr>
<tr>
<td>utf length<?php echo mb_strlen('日本語', 'UTF-8'); ?>
<input type="text" name="input" readonly value="日本語" size="<?php echo mb_strlen('日本語', 'UTF-8'); ?>">
</td>
</tr>
<tr>
<td>non utf length<?php echo strlen('日本語'); ?>
<input type="text" name="input" readonly value="日本語" size="<?php echo strlen('日本語'); ?>">
</td>
</tr>
</table>
The only correctly displayed string is the mb_strlen('日本語', 'UTF-8');
All the other textboxes are too long.
Is there any way to have the all the textboxes behave so that they are exactly the length of the string they display?