Jump to content

Archived

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

minuteman

problems getting vars read

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?

Share this post


Link to post
Share on other sites
Take a look at the string functions - maybe str_replace().

-> http://php.net/strings
-> http://php.net/str_replace

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites

×

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.