CarbonCopy Posted March 19, 2009 Share Posted March 19, 2009 I have code that looks like this: <$ SET_TITLE("TITLE_HERE") $> How can I use preg match or anything else to get the value of TITLE_HERE Thanks Link to comment https://forums.phpfreaks.com/topic/150167-preg-match-question/ Share on other sites More sharing options...
sasa Posted March 19, 2009 Share Posted March 19, 2009 <?php $test = '<$ SET_TITLE("TITLE_HERE") $>'; preg_match('/<\$\sSET_TITLE\("([^"]*)/i',$test,$out); print_r($out); ?> Link to comment https://forums.phpfreaks.com/topic/150167-preg-match-question/#findComment-788647 Share on other sites More sharing options...
CarbonCopy Posted March 19, 2009 Author Share Posted March 19, 2009 Thanks, that works perfectly. I adapted it to fit my needs, and here is the code I am using for anyone interested <?php preg_match('/<\$\sSET_TITLE\("([^"]*)/i',$html,$title); $title = $title[count($title)-1]; ?> Link to comment https://forums.phpfreaks.com/topic/150167-preg-match-question/#findComment-788661 Share on other sites More sharing options...
sasa Posted March 19, 2009 Share Posted March 19, 2009 you can use just $title = $title[1]; Link to comment https://forums.phpfreaks.com/topic/150167-preg-match-question/#findComment-788664 Share on other sites More sharing options...
CarbonCopy Posted March 21, 2009 Author Share Posted March 21, 2009 If it is found more than once, I want the last one found to be used Link to comment https://forums.phpfreaks.com/topic/150167-preg-match-question/#findComment-790501 Share on other sites More sharing options...
CarbonCopy Posted March 21, 2009 Author Share Posted March 21, 2009 Correction to the code thank you <?php /* Get the title */ if (preg_match_all('/\<\$\sSET_TITLE\("([^"]*)/i', $html, $title)) { $title = $title[1][count($title[1])-1]; } ?> Link to comment https://forums.phpfreaks.com/topic/150167-preg-match-question/#findComment-790503 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.