Jump to content

Recommended Posts

Hi all

 

i have text in database with the following stuff > and < and stuff like that .

well guests enter text that is saved to the database , and when it is printed out i don't want it to be parsed so converting all HTML entities to > and < is enough .

 

BUT

 

i want to allow some HTML tags to be converted back to normal

like <font size=4>text</font>

 

so i wrote the following regex where

$alowed_ones='font|b|center|i|a';

 

$data=preg_replace('/(<)('.$alowed_ones.')((\s)(.*))?(>)(.*)(<\/)('.$alowed_ones.')(>)/ims' , 
						'<\\2\\3>\\7</\\9>',
						$data,-1);

 

but for example if i $data was

<center><a href="fF">Xx"</a></center>

 

only the <center></center> is back to normal and the <a> tag is not parsed unless i run the preg_replace again !!!

any way to do it without having to call it back ???

 

plz help :(

 

Link to comment
https://forums.phpfreaks.com/topic/204864-preg_replace/
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.