Jump to content

**SOLVED** How to search and pull out


becu

Recommended Posts

ok, here's my problem:

$string = '<abc tag="test">sumtext goes here</abc>this is not supposed to show<abc>some more text goes here</abc>';

What should I do so I will only get everything inside [b]<abc[/b] and [b]</abc>[/b] tag?
preg_match didn't not work because it will pull out everything including "this is not supposed to show"
Thank you.
Link to comment
https://forums.phpfreaks.com/topic/7180-solved-how-to-search-and-pull-out/
Share on other sites

Try
[code]
$string = '<abc tag="test">sumtext goes here</abc>this is not supposed to show<abc>some more text goes here</abc>';

$res = array();
$p3 = $p2 = 0;

while (($p1 = strpos($string, '<abc', $p3)) !== false) {
       $p2 = strpos($string,'>',$p1);
       $p3 = strpos($string,'</abc>',$p2);
       $res[] = substr($string,$p2+1, $p3-$p2-1);
}

echo join ('<br />', $res);[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.