Page 1 of 1

Regular Expression is not working properly

Posted: Tue May 24, 2005 11:54 pm
by telic
Hi,

I am doing an admin panel for flash using PHP and XML, here I am using regular expression to find and replace text in the xml file.

This is the code I am using the find and replace operation

$string = "<page><![CDATA[".$text."]]></page>";
$pattern = "/<page>(.)*<\/page>/";
$contents = preg_replace($pattern,$string,$contents);


here “$text” content from textarea

if I am giving small text content it’s working fine, if I am giving four or more lines then this regular expression is not working properly.

please help me to rectify this issue....

Thanks in advance.

Posted: Wed May 25, 2005 12:16 am
by anjanesh
Try changing pattern to :
$pattern = "/<page>(.*?)<\/page>/is";

Are you sure you are using preg_replace correctly ? Your replacement argument seems to be the subject.
mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int limit] )

Posted: Wed May 25, 2005 6:22 am
by Chris Corbyn
:arrow: Moved to Regex :?

Posted: Wed May 25, 2005 6:28 am
by Chris Corbyn
Yeah anjanesh is right. You need the "s" modifier because . (dot) will not match multiple lines by itself :wink: