dreamwest Posted July 26, 2009 Share Posted July 26, 2009 I have a really long document, but only need a single word/s within two specific tags words here..... <link>only get this line</link> lots of words here..... How can i just get what is within the <link> tags?? Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/ Share on other sites More sharing options...
thewooleymammoth Posted July 26, 2009 Share Posted July 26, 2009 use explode <?php $content = " stuff stuff stuff <tag> what you want </tag> "; $value=explode("<tag>", $content); $value=explode("</tag>", $value); $what_you_want=$value[0]; ?> or you could learn to reg ex, which is much more efficient, but i hate it... http://www.regular-expressions.info/tutorial.html Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883519 Share on other sites More sharing options...
kickassamd Posted July 27, 2009 Share Posted July 27, 2009 Try this... preg_match("/<link>(.*)</link>/", $str, $matches); Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883582 Share on other sites More sharing options...
vineld Posted July 27, 2009 Share Posted July 27, 2009 I suppose you may be looking for more than one occurrence of the tag? If so, you would want to use preg_match_all instead. Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883594 Share on other sites More sharing options...
.josh Posted July 27, 2009 Share Posted July 27, 2009 Try this... preg_match("/<link>(.*)</link>/", $str, $matches); (.*?) Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883654 Share on other sites More sharing options...
Third_Degree Posted July 27, 2009 Share Posted July 27, 2009 kickassamd+ vineld + Crayon Violent = preg_match_all( "/<link>(.*?)</link>/", $str, $matches ); Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883660 Share on other sites More sharing options...
Third_Degree Posted July 27, 2009 Share Posted July 27, 2009 <?php $content = " stuff stuff stuff <tag> what you want </tag> "; $value=explode("<tag>", $content); $value=explode("</tag>", $value); $what_you_want=$value[0]; ?> ...$value[1] Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883663 Share on other sites More sharing options...
thewooleymammoth Posted July 27, 2009 Share Posted July 27, 2009 <?php $content = " stuff stuff stuff <tag> what you want </tag> "; $value=explode("<tag>", $content); $value=explode("</tag>", $value); $what_you_want=$value[0]; ?> ...$value[1] yea your right, my bad, typing to quick i guess Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883685 Share on other sites More sharing options...
Third_Degree Posted July 27, 2009 Share Posted July 27, 2009 yea your right, my bad, typing to quick i guess If you look at my sig, you'll know I'm no stranger to errors like that Quote Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883686 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.