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? Link to comment https://forums.phpfreaks.com/topic/104673-simple-php-help-needed/ 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"; Link to comment https://forums.phpfreaks.com/topic/104673-simple-php-help-needed/#findComment-535731 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 Link to comment https://forums.phpfreaks.com/topic/104673-simple-php-help-needed/#findComment-535760 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) Link to comment https://forums.phpfreaks.com/topic/104673-simple-php-help-needed/#findComment-535771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.