Re: [PHP] Preg_Replace $pattern syntax error

2008-06-10 Thread Daniel Brown
On Mon, Jun 9, 2008 at 8:07 PM, Graham Anderson [EMAIL PROTECTED] 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



[PHP] Preg_Replace $pattern syntax error

2008-06-09 Thread Graham Anderson

Hi

How can I convert the regular expression:p\s+style=padding-left: 
\s+(\d+)px;(.*?)/p

into a pattern that PHP will accept?

I am getting the error:
Warning: preg_replace() [function.preg-replace]: Unknown modifier '('  
in /Library/WebServer/Documents/tamagotchi/runtime/content/js/tiny_mce/ 
examples/tinymce_regex.php on line 24


I am very new to regular expressions and any help is appreciated.  
Something to do with escaping certain strings?

G


$html =EOB
TinyMCE is a span style=font-style: italic;platform/span
p style=text-align: center;We recommend a href=http://www.getfirefox.com 
 target=_blankFirefox/a /p

p style=padding-left: 30px;May the Regular Expression Find Me!/p
EOB;

$pattern='p\s+style=padding-left:\s+(\d+)px;(.*?)/p';
$replace= 'textformat indent=\\1\\2/textformat';
echo preg_replace($pattern,$replace, $html );



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



[PHP] Preg_Replace $pattern syntax error [solved]

2008-06-09 Thread Graham Anderson

I needed to add the ~ character as a delimiter. So, the below now works
$pattern='~p\s+style=padding-left:\s+(\d+)px;(.*?)/p~';

G


Hi

How can I convert the regular expression:p\s+style=padding- 
left:\s+(\d+)px;(.*?)/p

into a pattern that PHP will accept?

I am getting the error:
Warning: preg_replace() [function.preg-replace]: Unknown modifier  
'(' in /Library/WebServer/Documents/tamagotchi/runtime/content/js/ 
tiny_mce/examples/tinymce_regex.php on line 24


I am very new to regular expressions and any help is appreciated.  
Something to do with escaping certain strings?

G


$html =EOB
TinyMCE is a span style=font-style: italic;platform/span
p style=text-align: center;We recommend a href=http://www.getfirefox.com 
 target=_blankFirefox/a /p

p style=padding-left: 30px;May the Regular Expression Find Me!/p
EOB;

$pattern='p\s+style=padding-left:\s+(\d+)px;(.*?)/p';
$replace= 'textformat indent=\\1\\2/textformat';
echo preg_replace($pattern,$replace, $html );