There is such code:

<input name="name" value="<?= $name ?>"> 

the problem is that when displaying the name with "" the data is displayed incorrectly, what to do in this situation, $ name can be any composition

  • And if you write like that? <? php echo $ name; ?> - Gagablik
  • The same, already tried. There is most likely a matter of screening - Dmitry
  • You can of course write a crazy function of expansion of the line, screening, and after addition, but I think there should be a way to solve this problem much easier - Dmitry
  • Use htmlspecialchars for almost any output in html - vp_arth

2 answers 2

Use htmlspecialchars ()

 <input name="name" value="<?=htmlspecialchars($name);?>"> 

The function replaces quotes with " . When outputting in markup, everything will remain. I apply markup as proof.

 <input name="name" value="Раз два &quot;три&quot;"> 

  • already tried, did not work - Dmitry
  • 2
    @ Dmitriy what does it mean "did not work"? - andreymal
  • as I wrote above, $ name will be different (in the loop), your version is suitable for a particular case - Dmitry
  • 2
    @ Dmitriy it doesn’t hinder htmlspecialchars to work at all - andreymal
  • one
    This is the only correct answer - vp_arth

I had a similar problem. All output before quotes. Decided to translate the VARCHAR field into the TEXT field

  • Unfortunately, I already have it in text, I just didn’t indicate it above, if I understood you correctly type = "text" - Dmitry
  • There are many options, but the essence was that the output format should be done to make the text, and where you already know it better. - Art_K