[SOLVED] Making preg_match() look through whole string

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
HiddenS3crets
Forum Contributor
Posts: 119
Joined: Fri Apr 22, 2005 12:23 pm
Location: USA

[SOLVED] Making preg_match() look through whole string

Post 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?
Last edited by HiddenS3crets on Sun May 07, 2006 12:46 pm, edited 1 time in total.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post 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.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

preg_match_all()

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