Jump to content


Photo

**SOLVED** How to search and pull out


  • Please log in to reply
2 replies to this topic

#1 becu

becu
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 12 April 2006 - 08:40 AM

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 <abc and </abc> tag?
preg_match didn't not work because it will pull out everything including "this is not supposed to show"
Thank you.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 12 April 2006 - 08:16 PM

Try
$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);

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 becu

becu
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 15 April 2006 - 04:46 AM

Hi Barand,
Thank you so much for your help!
I really appreciate it!

Thanks again.

Have a great day! I will sure ask for help again :D




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users