...

View Full Version : Some preg_replace() help.



Dean440
02-06-2010, 04:07 PM
I've been tinkering around, but I'm not very experienced with using regexes. I've got some preg_replaces in place that format the HTML pretty nicely, but I have a problem I can't seem to take care of.

I need anything between
<li> and
</li> to have all newlines, tabs, and carriage returns removed.

I currently have code like this:
<li><a href="##">Stuff</a>

</li>

<li><a href="##">...

I'd like to get that formatted back to:

<li><a href="##">Stuff</a></li>
<li><a href="##">...

SKDevelopment
02-06-2010, 06:10 PM
You could do something like this:


$str = <<< STR
<li><a href="##">Stuff</a>

</li>

<li><a href="##">...
STR;
$str = preg_replace('/<li>(.*?)<\/li>/sie',"'<li>' . str_replace(array(\"\\r\",\"\\n\",\"\\t\"),'','\\1') . '</li>'",$str);
echo $str;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum