minuteman Posted October 4, 2006 Share Posted October 4, 2006 I'm trying to make dynamic metatags and can't seem to get the variables working. For instance , The title tag is stored in the db something like this - "Pay Per Click (PPC) For $continent " without the quotes and under the name $meta_title. The $continent value is passing through fine through the url, the $continent var gets echoed fine by itself no problem. But when I try to post the value with "echo 'meta_title = ', $meta_title ;"which includes the $continent var inside $meta_title, I can't get the value to echo. it echoes "Pay Per Click (PPC) For $continent" without the quotes. I know I can do something like "getThing".$continent for this example but that wouldn't work well for others. Can someone help me with this? Quote Link to comment Share on other sites More sharing options...
JaGeK Posted October 4, 2006 Share Posted October 4, 2006 Take a look at the string functions - maybe str_replace().-> http://php.net/strings-> http://php.net/str_replace Quote Link to comment Share on other sites More sharing options...
minuteman Posted October 4, 2006 Author Share Posted October 4, 2006 I couldn't see how either of those would do it but preg_replace looks like it would work. I used this code$string = $meta_title;$pattern = '$continent';$replacement = $continent;echo preg_replace($pattern, $replacement, $string);but I get this error - Warning: preg_replace(): No ending delimiter '$' found in .. line 108 (which is the echo preg... statementIf I echo each of the vars I getstring = Pay Per Click (PPC) Realestate Internet Marketing (RIM) For $continentpattern = $continentreplacement = south_americawhich seems right. If I can get "south_america" in the string in place of $continent I've got it.There's suppose to be slashes in the preg statement, one place said #, but either one always gives me syntax errors. Quote Link to comment Share on other sites More sharing options...
JaGeK Posted October 4, 2006 Share Posted October 4, 2006 [quote author=minuteman link=topic=110500.msg446855#msg446855 date=1159991434]I couldn't see how either of those would do it[/quote][code=php:0]<?php $meta_title = 'Pay Per Click (PPC) For $continent'; $continent = 'Australia'; echo str_replace('$continent', $continent, $meta_title);?>[/code] Quote Link to comment Share on other sites More sharing options...
minuteman Posted October 4, 2006 Author Share Posted October 4, 2006 hey hey hey! That got it! Thanks JaGeK javascript:void(0);Grin 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.