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 !?!?! Quote Link to comment Share on other sites More sharing options...
trq Posted May 4, 2007 Share Posted May 4, 2007 if(preg_match("/$meta_tag/i",$string)) { Quote Link to comment 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 ... Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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() ? Quote Link to comment 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!! :-) Quote Link to comment 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.