Jump to content

Weird Behavion When Retrieving A String From A Text Field


p3ndu

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.