Reputation: 635
I try to show this string : «let's go» in a the value of an input tag
i wrote: $chaine="let's go";
echo "<input type=text name=test value='".$chaine."'>";
result: let
What can i do to show the correct string in this case ?
Upvotes: 4
Views: 3796
Reputation: 86406
You can look at htmlentities()
htmlentities($chaine, ENT_QUOTES) ;
Upvotes: 4
Reputation: 1233
use htmlspecialchars
echo "<input type=text name=test value='".htmlspecialchars($chaine, ENT_QUOTES)."'>";
Upvotes: 8
Reputation: 131891
This produces
<input type=text name=test value='let's go'>
You can see, that for HTML (--> your Browser) the value ends after "let". Everything after that is invalid (but ignored). Escape
$chaine = "let\'s go";
However, in HTML double quotes are prefered and omitting the quotes is also no good style
$chaine="let's go";
echo '<input type="text" name="test" value="'.$chaine.'">';
In this case you must escape every double quote.
Upvotes: -1