Jump to content

[SOLVED] Converting back from htmlentities


AdRock

Recommended Posts

I have used htmlentities for inserting into the database and I get what's in the database into a form for editing.

 

Is there a way i can convert back to html but only what i want to convert back.  I suppose the best way is to use str_replace()

 

I want to keep images as they are in the database using <img src but everything else i want to convert back.

 

What about converting it all back to html and use str_replace on the images to put them back to htmlentities?

 

Only works on a 'global' level; that is, you cannot specify for it to ignore some things. 

 

You would have to use some regex to convert only the ones you want. Unless your target tags will always have the same content (attributes, values, same order/format), you will have to use a real regex function like preg_replace, instead of str_replace.

i tried using preg_replace and it works when i just have a small test script but when i try using data from a database it doesn't work

 

is this right?

while ($row = $result->fetch()) {
    $data = $row['content'];
    $find = array ('/<img/', '/.jpg">/');
    $replace = array ('<img', '.jpg">');

    $content = preg_replace ($find, $replace, $data);
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.