Re: Preg_Replace $pattern syntax error

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

 



On Mon, Jun 9, 2008 at 8:07 PM, Graham Anderson <grahama1970@xxxxxxxxx> wrote:
> Hi
>
> How can I convert the regular expression:
>  <p\s+style="padding-left:\s+(\d+)px;">(.*?)</p>
> into a pattern that PHP will accept?
[snip!]

    Change this:
$pattern='<p\s+style="padding-left:\s+(\d+)px;">(.*?)</p>';

    To this:
$pattern='/<p\s+style="padding-left:\s+(\d+)px;">(.*?)<\/p>/Uis';

    This adds the delimiters (/) to the beginning and end of the
string, and escapes the slash in the </p> so it doesn't kick-out
early, leaving trailing characters.  After the ending delimiter, it
tells preg_replace() to be "Ungreedy", "CASE-iNSENSITIVE", and to feel
free to cross over newline boundaries (with the 's' modifier).

    From there, you can modify your regexp as needed.

    One of the absolute best resources for regexp's on the 'Net today,
in my opinion, is here:

        http://www.regular-expressions.info/

    It's even good for those of us who forget things years later.... ;-P

-- 
</Daniel P. Brown>
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[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