Page 1 of 1

Need preg_split and regex help

Posted: Tue Mar 21, 2006 9:34 am
by fastfingertips
Hello i have following string:

Code: Select all

<html>
	<head>
		<title><<:title:>></title>
	</head>
	<body>
		<<:foreach (:user: as $key=>$value):>>
		<tr>
			<td><<:user:username:>></td>
			<td><<:user:password:>></td>
			<td><<:user:email:>></td>
		</tr>
		<<:endfor:>>
	</body>
</html>
And i will like to use preg_split to separate:

Code: Select all

<<:foreach (:user: as $key=>$value):>>
		<tr>
			<td><<:user:username:>></td>
			<td><<:user:password:>></td>
			<td><<:user:email:>></td>
		</tr>
		<<:endfor:>>
From the rest of the code. My question is how to make the regex because no matter what i've tried i failed

Posted: Tue Mar 21, 2006 10:09 am
by feyd

Code: Select all

$foo = preg_split('#(<<:foreach.+?<<:endfor:>>)#is', $text, PREG_SPLIT_DELIM_CAPTURE);

Posted: Wed Mar 22, 2006 1:25 am
by fastfingertips
Thank you feyd but my problem is the same. That portion (<<:foreach ---- endfor:>>) i want to be storred in a different array element. As it seems i cannot avoid preg_match :(

Posted: Wed Mar 22, 2006 1:44 am
by feyd
no you don't.

Code: Select all

$foo = preg_split('#(<<:foreach.+?<<:endfor:>>)#is', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
works, I just tried it. (I forgot the limit argument in my previous post.)

Posted: Wed Mar 22, 2006 1:46 am
by fastfingertips
Yhea indeed is working i also tried.

Please send me your address to knowe where should i send the bax with your favourite beer :).

This problem has been solved.

Thank you