Page 1 of 1

[SOLVED] Making preg_match() look through whole string

Posted: Sun May 07, 2006 12:04 pm
by HiddenS3crets
This is my preg_match() sequence:

Code: Select all

preg_match("/<([a-z]*)?\>(.*?)\<\/([a-z]*)?\>/s", $str, $matches);
In short, people submit a string that can have multiple sections of source code:

Code: Select all

Hello World in php:
<php>
<?php
echo "Hello World";
?>
</php>

And in java:
<java>
System.out.println("Hello World");
</java>

That's basically it
Assuming that someone submitted that, I want preg_match() to recognize the <php> section and <java> section.

Currently it will only recognize the php section though. Is there a way I can make it traverse through $str until the last occurrance instead of it only matching one regex?

Posted: Sun May 07, 2006 12:14 pm
by Oren
Can you explain better what you need?

P.S I'm not a mod so I can't move your post, but please post in the correct forum - Regex.

Posted: Sun May 07, 2006 12:15 pm
by Burrito
preg_match_all()

edit: Oren, he's not asking for help on a regular expression...this is in the correct forum.