champrock Posted May 8, 2008 Share Posted May 8, 2008 hi i have some raw data from which i ned to extract some useful pieces.. data is in this form <Date>2008-05-07 22:57:18</Date> <Timestamp>23123123213</Timestamp> <Link>[b] I WANT TO EXTRACT THIS 1[/b] </Link> <Category id="12">Other</Category> <User>EXAMPLE</User> <Date>2008-05-07 22:57:18</Date> <Timestamp>23123123213</Timestamp> <Link>[b] I WANT TO EXTRACT THIS 2[/b] </Link> <Category id="12">Other</Category> <User>EXAMPLE</User> <Date>2008-05-07 22:57:18</Date> <Timestamp>23123123213</Timestamp> <Link>[b] I WANT TO EXTRACT THIS 3[/b] </Link> <Category id="12">Other</Category> <User>EXAMPLE</User> i want to extract all instances of "I WANT TO EXTRACT THIS" PLease suggest what regex do i use? I am trying to do this with preg_match_all? Is this right? Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted May 8, 2008 Share Posted May 8, 2008 try this... $line = "<Link> I WANT TO EXTRACT THIS 3 </Link>"; if (preg_match("/\<Link\>/", $line)) { $clean = preg_replace("/(\<Link\>)|(\[b\])|(\[\/b\])|(\<\/Link\>)/", "", $line); } print "$line\n"; print "$clean\n"; Quote Link to comment Share on other sites More sharing options...
champrock Posted May 8, 2008 Author Share Posted May 8, 2008 thanks a lot. One more thing, can u please tell the regexp for matching all links ? I want to extract all links (http://) from raw data ? thanks Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted May 8, 2008 Share Posted May 8, 2008 try changing preg_match("/\<Link\>/", $line) to preg_match("/http:\/\//", $line) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.