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 Quote 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); ?> Quote 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]; ?> Quote 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]; Quote 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 Quote 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]; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/150167-preg-match-question/#findComment-790503 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.