Jump to content

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);
}

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.