Page 1 of 1

Help in Searching with Regular Expression

Posted: Sat Aug 16, 2003 2:37 am
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

Posted: Sat Aug 16, 2003 2:47 pm
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