Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: double quotes don't show in input value, but are shown in normal echo

I have some strings in the database like SNEAKERS "SUPER STAR" GOLDEN GOOSE. These are the titles for some products. When I output it normally inside a <p> it shows the quotes, but when I echo it inside an input value, <input type="text" value="<?= $product->title ?"> the string gets truncated before the first double quote, so the value becomes just SNEAKERS.

Is there a way I can output the double quotes inside the value of an input ?

EDIT: The closing tag was a typo, in the code it is closed.

like image 736
C. Ovidiu Avatar asked Jan 10 '23 02:01

C. Ovidiu


1 Answers

Use htmlspecialchars like so:

htmlspecialchars($product->title);

i.e

<input type="text" value="<?= htmlspecialchars($product->title) ?>">
like image 193
Wayne Whitty Avatar answered Jan 29 '23 03:01

Wayne Whitty