Link to home
Start Free TrialLog in
Avatar of willsherwood
willsherwood

asked on

PHP htmspecialchars returns empty string

here are various tests that show what does and doesn't work.  I cannot figure out what's wrong with the one that doesn't work.
The original text is much longer, but this is whittled down to a small test case.
(The original text is from a field in a db)

---
WORKS:
<?= htmlspecialchars("
                    <p><strong> Haven</strong>  at a very affordable  price</p>
                              ", ENT_QUOTES)?>
                             
                      RESULTS:    &lt;p&gt;&lt;strong&gt; Haven&lt;/strong&gt;  at a very affordable  price&lt;/p&gt;

---
DOESN'T WORK:   ("  satisfactory use.  "  was added in the string)
<?= htmlspecialchars("
                    <p><strong> Haven</strong>  at a very affordable  price  satisfactory use.  </p>
                              ", ENT_QUOTES)?>

                      RESULTS:       (blank)

---
DEBUG:
<?= strlen( htmlspecialchars("
                    <p><strong> Haven</strong>  at a very affordable  price  satisfactory use.  </p>
                              ", ENT_QUOTES))?>

                      RESULTS:       0

---

I also did a copy and paste back in the same place to "launder" the text thru notepad++  just in case there was a
stray special character, but no difference.

How to debug?    

thanks
ASKER CERTIFIED SOLUTION
Avatar of Mark Brady
Mark Brady
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of willsherwood
willsherwood

ASKER

i gave up and just used a brute-force replace tha works.

str_replace('"', "&quot;",
         str_replace("'", "&apos;", $Description)   )