...

View Full Version : Difficulty with PHP regex



Adamcox82
02-27-2010, 12:26 PM
I'm having real difficulty getting a PHP regex working and need some help! I have pages containing text in the following format:


Text
<gallery>
filename1|description1
filename2|description2
filename3|description3
</gallery>
More text

I'm trying to create a regex which will match the entire text within the gallery tags, but I seem to be coming across a problem due to the carriage returns involved. My current expression is <*.+gallery> which returns only the tags themselves (and not the contents), and the contents aren't matched unless I change the text's format to:


Text
<gallery>filename1|description1filename2|description2filename3|description3</gallery>
More text

Any suggestions on what I could add or change to make this work as desired with multi-line text?

koko5
02-27-2010, 12:49 PM
Hi, try something like this


$s='Text
<gallery>
filename1|description1
filename2|description2
filename3|description3
</gallery>
More text';
$arr = array();
preg_match_all('#(?<=\<gallery\>)(.*)?(?:\</gallery\>)#misux',$s,&$arr);
print_r($arr);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum