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?? 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 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); 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. 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); (.*?) 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 ); 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] 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 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 Link to comment https://forums.phpfreaks.com/topic/167547-getbetween/#findComment-883686 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.