I'm having a problem displaying the value of textbox that has an apostrophe. In my code below, the result will only show sample
without an s. How can I make the s
show?
<?php
$str = "sample's";
echo "<input type='text' value='".$str."' />";
?>
You can use addslashes function
$str = addslashes("sample's");
While echoing use
echo stripslashes($str);
将htmlspecialchars()
与ENT_QUOTES
echo "<input type='text' value='".htmlspecialchars($str,ENT_QUOTES)."' />";
You could try either:
echo '<input type="text" name="name" value="'.$str.'" />';
or
echo "<input type='text' name='name' value=\"{$str}\" />";
Try this
$str = "sample's";
echo "<input type='text' value='".str_replace("'", ''', $str)."' />";
Note I have useed ISO Latin-1 code for HTML special character here. You can find special characters related codes here https://www.utexas.edu/learn/html/spchar.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.