p3ndu Posted October 9, 2012 Share Posted October 9, 2012 Hi guys, I am creating a script that retrieves some products from an OpenCart database. Everything is fine except one of the fields that gets a description surrounded by paragraph tags from a TEXT column in one of the tables. The weird behavior is that no matter what I do with the string, I can't strip the tags from it ( I tried using strip_tags, str_replace, preg_replace and everything else I could have thought! ). The PHP version is :5.2.17 MySQL Client API version 5.1.65 The code I use to retrieve that certain string is : $query_desc = mysql_query("SELECT description FROM product_description WHERE product_id = $id_produs AND language_id = 2"); while($row_desc = mysql_fetch_assoc($query_desc)) { // $desc = preg_replace("/<[^>]*>/","",$row_desc['description']); // $desc = var_dump($desc); $desc = $row_desc['description']; } If I copy the output of $desc from the browser, save it in a PHP file and remove the tags using any of the methods mentioned above, it works! Also, var_dump tells me it's a string and everything seems ok. Has anyone encountered such weird behavior before? Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 9, 2012 Share Posted October 9, 2012 What's the output of the var_dump? If the <p> tags are showing up on your page, rather than in the source, then the text has already been run through htmlentities. Try doing html_entity_decode on it before removing it. Otherwise, show us exactly what you see. Also, that code doesn't echo anything. Show us the code that echo's the string. Quote Link to comment Share on other sites More sharing options...
p3ndu Posted October 9, 2012 Author Share Posted October 9, 2012 Wow! That was fast and GREAT. The html_entity_decode() worked, it is now doing it's job! Thank you so very much, sir! Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 9, 2012 Share Posted October 9, 2012 You're welcome ma'am. You should find the source of where the tags are being converted to entities and fix it there, FYI. Quote Link to comment Share on other sites More sharing options...
p3ndu Posted October 9, 2012 Author Share Posted October 9, 2012 Thanks ma'am. Noticed you're not a sir after I got the code to work, was overexcited! The problem with the entities is called OpenCart and the fact that the former "developer" migrated everything from Wordpress to it leaving a total mess. And I know have to fix it. Thank you so very much again! Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 9, 2012 Share Posted October 9, 2012 In that case, you'll want to fix the database entries, but if you're happy with it I guess it's not a huge deal. *shrug*. You're welcome. Quote Link to comment Share on other sites More sharing options...
p3ndu Posted October 9, 2012 Author Share Posted October 9, 2012 It is a huge deal. But at first I had to get some basic functionality on the site, and with time I will clean the database and set everything right. Quote Link to comment 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.