tags:

views:

79

answers:

2

Hi In my php project i have a value containg special charectors like ",' etc ( " 5 " inches , '3.5' inches etc) . But it's not appear in a text field . How i display this is it possible to display this value in a text box ? Does any one help me ...

+1  A: 

Use htmlentities:

<input value="<?php echo htmlentities($value);?>">
Emil Vikström
+1  A: 

I suppose your "text box" is an HTML <input> element ?

If so, you are displaying it using something like this :

echo '<input name="..." value="' . $yourValue . '" />';

If it's the case, you need to escape the HTML that's contained in your variable, with htmlspecialchars :

echo '<input name="..." value="' . htmlspecialchars($yourValue) . '" />';

Note that you might have to add a couple of parameters, especially to specify the encoding your are using.


This way, considering $yourValue has been initialized like this :

$yourValue = '5 " inches';

You'll get from this generated HTML :

<input name="..." value="5 " inches" />

To that one, which works much better :

<input name="..." value="5 &quot; inches" />
Pascal MARTIN