Hi, I have this example string <tag> some random string here </tag> <tag> some random this is what we want more random </tag> <tag> another random string here </tag> Code (markup): This code works: <?php if(preg_match('/<tag>(.*this is what we want.*)<\/tag>/si', $string) { echo 'Ok'; } ?> PHP: But it works also if we have the following string: <tag> some random string here </tag> some random this is what we want more random <tag> another random string here </tag> Code (markup): I don't want the regexp to work for the above string because it doesn't wrapped with <tag> and </tag> Any ideas how should I use the regexp?
This will work; <?php $str = "<tag> some random string here </tag> some random this is what we want more random <tag> another random string here </tag>"; preg_match_all('/<tag>(.*?)<\/tag>/si', $str, $ff); print_r($ff); ?> PHP: OUTPUT: Array ( [0] => Array ( [0] => <tag> some random string here </tag> [1] => <tag> another random string here </tag> ) [1] => Array ( [0] => some random string here [1] => another random string here ) ) Code (markup):
@lukeg32 thanks, but I want to find "this is what we want" and it should be wrapped with <tag> and </tag>. The phrase "this is what we want" should be used in the regexp because it is important
can u suggest me another function batter then preg_match. b/c i always gets error while using this funtion