if a user enters “book” in the input box, and click submit, it shows “book” in the box.
if a user enters “single quotation” in the box, it shows “backward slash + single quotation” in the box.
In order to remove “backward slash”, I modified the code above as the code below by inserting “$key=str_replace(”'“, “'”, $key);”
It would probably be better if you tell us about the real problem you are trying to solve with this code. What is the high level overview of what you are doing?
* Is this still part of your php5 to php7 conversion?
I am making of searching page on the way of building a site.
after a user enters a keyword, it is, I just think, good to show the keyword in the box.
Most web site including google.com is doing like that.
So I ran your original code and it worked as expected. Not really seeing where you are getting a backslash. In your url you should see something like:
http://127.0.0.1:8000/d7.php?key=jjj%27kkk
Be sure you don’t have any magic quote nonsense going on. You should never have to do the sort of str_replace stuff in your second example.
What you are missing is the escaping of html output characters. If the user enters a character such < which html uses then problems would definitely ensue. You always need to escape your output data:
$key = isset($_GET['key']) ? $_GET['key'] : '';
// HTML escape your values before sending back to the browser
$key = htmlspecialchars($key, ENT_COMPAT);
$html = <<<EOT
<div>Key Value: {$key}</div>
<form action="index.php" method="get">
<input type="text" name="key" value="{$key}">
<input type="submit">
</form>
EOT;
echo $html;
You can lookup htmlspecialchars in the docs to see what all it does.
And while off-topic, using what is known as the heredoc notation can save you a considerable amount of stress when generating html.
And really off-topic but always use prepared statements for your database stuff otherwise you will run into a host of problems.
I like to remove the backslash in displaying.in the input box.
I like to display a single quotation mark only instead of a backslash and single quotation mark in the input box.
I like to remove the backslash in displaying.in the input box.
I like to display a double quotation mark only instead of a backslash and double quotation mark in the input box.