Jump to content

problems getting vars read


minuteman

Recommended Posts

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?
Link to comment
https://forums.phpfreaks.com/topic/22995-problems-getting-vars-read/
Share on other sites

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... statement

If I echo each of the vars I get
string = Pay Per Click (PPC) Realestate Internet Marketing (RIM) For $continent
pattern = $continent
replacement = south_america

which 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 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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.