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
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.
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.