...

View Full Version : Regex problem..



cyphix
02-13-2006, 04:51 PM
Hey guys.. having some problem with this regex..... example..

Original text:



Text here:<BR>&nbsp;&nbsp;More text


I am trying to remove the "<BR>&nbsp;&nbsp;" part but also account for lowercase, <br />/<br/>'s & also zero or more &nbsp; & not always just the two; but all my code seems to do is remove the <BR> tag & leave the &nbsp;'s.......

Here is what I have tried..



$ff = preg_replace('~<br(/| /)?(&nbsp;)*>~i', ' ', $ff);


also tried..



$ff = preg_replace('~(<br(/| /)?(&nbsp;)*)>~i', ' ', $ff);


..but they both gave the same result.

Thanks for any help! :)

dumpfi
02-13-2006, 06:10 PM
Try:
$ff = preg_replace('#<br(/| /)?>|&nbsp;#i', ' ', $ff);dumpfi

cyphix
02-13-2006, 07:45 PM
Thanks.. that worked; but I end up with the items replaced with 3 spaces instead of one. :confused:

Element
02-13-2006, 10:12 PM
Maybe thats because you have three things in the string being change to a space.......

marek_mar
02-13-2006, 10:58 PM
Try


$ff = preg_replace('#<br(/| /)?>(?:&nbsp;)*#i', ' ', $ff);

cyphix
02-17-2006, 09:24 PM
Thank you! That worked a charm! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum