Need preg_split and regex help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Need preg_split and regex help

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$foo = preg_split('#(<<:foreach.+?<<:endfor:>>)#is', $text, PREG_SPLIT_DELIM_CAPTURE);
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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 :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.)
fastfingertips
Forum Contributor
Posts: 242
Joined: Sun Dec 28, 2003 1:40 am
Contact:

Post 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
Post Reply