Jump to content


Photo

problems getting vars read


  • Please log in to reply
4 replies to this topic

#1 minuteman

minuteman
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationFlorida

Posted 04 October 2006 - 05:35 PM

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?
C\'est la vie!

#2 JaGeK

JaGeK
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationNRW, Germany

Posted 04 October 2006 - 06:14 PM

Take a look at the string functions - maybe str_replace().

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

#3 minuteman

minuteman
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationFlorida

Posted 04 October 2006 - 07:50 PM

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.
C\'est la vie!

#4 JaGeK

JaGeK
  • Members
  • PipPip
  • Member
  • 20 posts
  • LocationNRW, Germany

Posted 04 October 2006 - 07:56 PM

I couldn't see how either of those would do it


<?php
  $meta_title = 'Pay Per Click (PPC) For $continent';
  $continent = 'Australia';
  echo str_replace('$continent', $continent, $meta_title);
?>


#5 minuteman

minuteman
  • Members
  • PipPip
  • Member
  • 12 posts
  • LocationFlorida

Posted 04 October 2006 - 08:00 PM

hey hey hey! That got it! Thanks JaGeK javascript:void(0);
Grin
C\'est la vie!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users