njdubois Posted March 4, 2015 Share Posted March 4, 2015 Hello friends! I have to be missing something, and I hope you can point it out! $output = htmlspecialchars("isn't it nice & clean"); echo $output; outputs: isn't it nice & clean I inspect element in chrome and I see: isn't it nice & clean Shouldn't it be: isn't it nice & clean ?? Confused! Thanks Nick Quote Link to comment https://forums.phpfreaks.com/topic/295098-htmlspecialchars-question/ Share on other sites More sharing options...
mac_gyver Posted March 4, 2015 Share Posted March 4, 2015 single quotes aren't operated on by default. see the list of flag parameters in the php.net documentation - http://php.net/htmlspecialchars Quote Link to comment https://forums.phpfreaks.com/topic/295098-htmlspecialchars-question/#findComment-1507524 Share on other sites More sharing options...
njdubois Posted March 4, 2015 Author Share Posted March 4, 2015 But & is, and it wasn't showing in inspect elements. I finally found a google search hit that stated to "view source" and there was the &. I added ENT_QUOTES so the code looks like: $output = htmlspecialchars("isn't it nice & clean", ENT_QUOTES); echo $output; and now I view source instead of inspect element and I get: isn't it nice & clean I had seen many posts to "htmlspecialchars not working" and they all said if you inspect element you will see. Yet inspect element didn't work. Did something change? Either way, foolish of me to trust inspect element. Thanks for the reply! Nick Quote Link to comment https://forums.phpfreaks.com/topic/295098-htmlspecialchars-question/#findComment-1507525 Share on other sites More sharing options...
Ch0cu3r Posted March 4, 2015 Share Posted March 4, 2015 Inspect element has nothing to do with PHP. It is a feature of the web browser. To see the actual output from your PHP script you need to right click > view source Inspect element is most likely prettifying the HTML. It is not a sign htmlentities is not working. Quote Link to comment https://forums.phpfreaks.com/topic/295098-htmlspecialchars-question/#findComment-1507528 Share on other sites More sharing options...
CroNiX Posted March 5, 2015 Share Posted March 5, 2015 You can also put it in between <pre> tags to view the raw HTML output before your browser converts the entities back to their respective symbols. Quote Link to comment https://forums.phpfreaks.com/topic/295098-htmlspecialchars-question/#findComment-1507591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.