Help in Searching with Regular Expression

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
altamash
Forum Newbie
Posts: 8
Joined: Mon Jul 21, 2003 6:03 am

Help in Searching with Regular Expression

Post by altamash »

Hi to all,
My aim is to pickup the substring from the $test between <p> & </p> and having word "code" inside.

I m using following code::

$test = "before<p>my code is yyyyyyyyXH99</p><p>This is second line</p>after";
print strlen($test);print"<br>";
print eregi( "<p>.*code.*</p>" ,$test,$array);
print "<br>\$array[0] :: $array[0]";

I m getting the following output::

62
56
$array[0] ::
my code is yyyyyyyyXH99

This is second line

I dont wana "This is second line" in my output
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

is this on a string or array????


for a string

Code: Select all

$what_we_want=preg_match('|(<p>[\w\W]*code[\w\W]*</p>)|i', $text);

double check, but i beleive the () make it return the text that matches instead of a 1 or 0
Post Reply