ok this is stupid I know:
why cant I display my apostrophied text in my edit field?

text is this "I'm on a plane"

its inserted to the db with mysql_real_escape_string and echoes on to the page as raw text fine

but when echoing into a text input area it messes up the html and gives up after the apostrophe - which I understand - its an html problem not a php or mysql problem

<input type='Text' name='blg_txt' size='60' value=' <?php echo $blg_txt ;?>' >

but what on earth is the solution?

  • ok well a textarea displays it ok - is that the only solution?

    You could convert your text first using htmlspecialchars which would replace them to quotes, I think

      Be sure to use the ENT_QUOTES modifier with htmlspecialchars():

      <input type='Text' name='blg_txt' size='60' value='<?php 
      echo htmlspecialchars($blg_txt, ENT_QUOTES); ?>' >
      

        thanks nogdog - just seems bizarre that I never came across this problem before

        damn, maybe I should convert all my plain text input boxes to do that..

          cretaceous wrote:

          thanks nogdog - just seems bizarre that I never came across this problem before

          damn, maybe I should convert all my plain text input boxes to do that..

          To be on the safe side, it's a good practice for any variable being output as text in [X]HTML when that variable's content is not intended to have any HTML mark-up itself.

            Write a Reply...