Hi, Tuesday, September 14, 2004, 6:04:44 AM, you wrote: r> Hello, would someone please help me with my regular expressions? They are so r> complex!
r> Here is what I need to do. I have a string with contents similar to the r> following: r> <BLOCK NAME="TOP"> r> (a bunch of markup code) r> </BLOCK> r> In other words, the name of the block is not known at runtime. They could be r> anything really! r> I need a way to parse through this string, and make new strings with names r> like $TOP, $BOTTOM, $WAYOVERHERE, that contain their markup code, but not the r> <BLOCK> tags. r> Any help would be greatly appreciated! r> -Samuel This should get you started: <? function callback($a){ print_r($a); } $str = <<<END <BLOCK NAME="TOP"> (a bunch of markup code) </BLOCK> <BLOCK NAME="BOTTOM"> (a bunch of markup code) </BLOCK> <BLOCK NAME="WAYOVERHERE"> (a bunch of markup code) </BLOCK> END; preg_replace_callback('!<BLOCK NAME="(.*?)">(.*?)</BLOCK>!is','callback',$str); Use the call back function to build whatever you need. -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php