Preg_Match?

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
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Preg_Match?

Post by Mr Tech »

Hey there!

I'm using the preg_match() function to retreieve information from a file. This is an example of the file:

Code: Select all

<?php
$title = <<<EOF
Title goes here
EOF;
$body = <<<EOF
Content goes here
EOF;
?>
Now when I use this query:

Code: Select all

<?php
if( preg_match( "/title = <<<EOF([^\|]*)EOF;/is", $content, $match ) )
$title = $match[1];
?>
It get the content from the $title all the way down to the end of the $body tag when I only want the $title. I tried ([^\EOF;]*) but it didn't work...

Any suggestions?
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

(&#1111;^\|]*?)
User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Awesome works well! Also, it it possible to remove this part: [^\|] so it's like (*?) I tried it but it didn't work because I don't want it to not work if there is a | in the text...

Thanks again!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

User avatar
Mr Tech
Forum Contributor
Posts: 424
Joined: Tue Aug 10, 2004 3:08 am

Post by Mr Tech »

Thanks, will do.
Post Reply