Re: help with preg_replace pattern

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 26, 2010 at 10:37 PM, Rob Gould <gouldimg@xxxxxxx> wrote:

> It appears that IE renders it's display: none in all caps while Firefox and
> other browsers pass it back in lowercase.  This throws off my php line of
> code the is supposed to nuke blank bullets from a string of text:
> $bl =
> <LI style="DISPLAY: none" id=bullet_ug2_col5_8></LI>
> <LI style="DISPLAY: none" id=bullet_ug2_col4_8></LI>
> <LI style="DISPLAY: none" id=bullet_ug2_col3_8></LI>
> <LI style="DISPLAY: none" id=bullet_ug2_col2_8></LI>
> <LI style="DISPLAY: none" id=bullet_ug2_8></LI>
> <LI style="DISPLAY: none" id=bullet_ug1_col4_8></LI>
> <LI style="DISPLAY: list-item" id=bullet_ug1_col3_8>Reserved Frontstretch
> Tower Ticket to the NextEra Energy Resources 250 on Friday Night </LI>
> <LI style="DISPLAY: list-item" id=bullet_ug1_col2_8>Reserved Frontstretch
> Tower Ticket to the Camping World 300 on Saturday </LI>
> <LI style="DISPLAY: list-item" id=bullet_2_8>Reserved Frontstretch Tower
> Ticket to the Daytona 500 on Sunday </LI>
> <LI style="DISPLAY: none" id=bullet_addon_col2_8></LI>
> <LI style="DISPLAY: none" id=bullet_addon3_8></LI>
> <LI style="DISPLAY: none" id=bullet_option2_col4_8></LI>
> <LI style="DISPLAY: none" id=bullet_option2_col3_8></LI>
> <LI style="DISPLAY: none" id=bullet_option2_col2_8></LI>
> <LI style="DISPLAY: none" id=bullet_option2_col1_8></LI>
> <LI style="DISPLAY: none" id=bullet_option3_col4_8></LI>
> <LI style="DISPLAY: none" id=bullet_option3_col3_8></LI>
> <LI style="DISPLAY: none" id=bullet_option3_col2_8></LI>
> <LI style="DISPLAY: none" id=bullet_option3_col1_8></LI>
> <LI style="DISPLAY: none" id=bullet_option4_col4_8></LI>
> <LI style="DISPLAY: none" id=bullet_option4_col3_8></LI>
>
> I want to keep the "DISPLAY: list-item" lines, and nuke all the others.
> The below above are sent to PHP in a variable called $bl.  I then try to
> nuke the "DISPLAY: none" lines with something like:
>
> $pattern = '/<li[^>]*style="display: none[^>]*>/';
> $bl = preg_replace($pattern,'',$bl);
>
> $pattern = '/<li[^>]*style="DISPLAY: none[^>]*>/';
> $bl = preg_replace($pattern,'',$bl);
>
> But it appears that the case-sensitivity fix is not just a matter of making
> the letter capitals.  I'm sure someone who knows more than I about
> preg_replace will see the
> immediate error of my ways.  Any advice is greatly appreciated.
>
>
>
>
>
>
Your regex is looking for case-sensitive matches, which given the example
below, would preclude all of your list items (they all start with "<LI", not
"<li".)

Try using a case insensitive regex (e.g., $bl = preg_replace($pattern
= /<li[^>]*style="DISPLAY: none[^>]*>/i','',$bl);

(Note the "i" after the search pattern above.)

Adam


-- 
Nephtali:  PHP web framework that functions beautifully
http://nephtaliproject.com

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux