techiefreak05 Posted May 4, 2007 Share Posted May 4, 2007 i have a code that is SUPPOSED to check if a certain META tag is in the header of a webpage.... and guess what? it saying the meta tag isnt found!! look, heres the code: <?php $meta_tag="<META name=zwm-verifyDomain content=" . $url_token . ">"; $file = "http://" . $_GET[verify]; $string = htmlentities(file_get_contents($file)); if(preg_match('/$meta_tag/i',$string)){ echo "found string"; }else{ echo "string not found"; } ?> and here is the value of $meta_tag when echoed out: <META name=zwm-verifyDomain content=2hcal6bwu495bdazs8nlm2lpk2q92q3e7ko67g5q3ewscp7cx9pniviehrz1v9qeg9ycrz> any ideas !?!?! Link to comment https://forums.phpfreaks.com/topic/49927-solved-help-code-error-is-stumping-me/ Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 if(preg_match("/$meta_tag/i",$string)) { Link to comment https://forums.phpfreaks.com/topic/49927-solved-help-code-error-is-stumping-me/#findComment-245020 Share on other sites More sharing options...
techiefreak05 Posted May 4, 2007 Author Share Posted May 4, 2007 adding the doubles quotes instead of the single quotes didnt work ... Link to comment https://forums.phpfreaks.com/topic/49927-solved-help-code-error-is-stumping-me/#findComment-245024 Share on other sites More sharing options...
btherl Posted May 4, 2007 Share Posted May 4, 2007 Try printing out the pattern you are matching, as well as the string you are matching against. They must match exactly. Link to comment https://forums.phpfreaks.com/topic/49927-solved-help-code-error-is-stumping-me/#findComment-245080 Share on other sites More sharing options...
techiefreak05 Posted May 4, 2007 Author Share Posted May 4, 2007 I did tat. and they do match EXACTLY. I echoed out $string, which is the source of the webpage with the META TAG, and i echoed $meta_tag, and yeah, they do match Link to comment https://forums.phpfreaks.com/topic/49927-solved-help-code-error-is-stumping-me/#findComment-245304 Share on other sites More sharing options...
techiefreak05 Posted May 4, 2007 Author Share Posted May 4, 2007 is there something wrong with my code? can you put variables inside preg_match() ? Link to comment https://forums.phpfreaks.com/topic/49927-solved-help-code-error-is-stumping-me/#findComment-245477 Share on other sites More sharing options...
techiefreak05 Posted May 5, 2007 Author Share Posted May 5, 2007 !!! I got it!! You have to treat variables in preg_match() as if it was echoed... like this: <?php if(preg_match('/' . $meta_tag . '/i',$string)){ ?> it just came to me, i tried it. and it works!! :-) Link to comment https://forums.phpfreaks.com/topic/49927-solved-help-code-error-is-stumping-me/#findComment-245988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.