Jump to content


Photo

Merging a string inside a string.


  • Please log in to reply
2 replies to this topic

#1 XOpa

XOpa
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 April 2006 - 10:25 PM

I'm confussed and annoyed at this. I have a string in my config file called
$Gallery_Name_1_NameDate = "TEST 1"; and
$Gallery_Name_2_NameDate = "TEST 2";

In one of the pages I have the URL string $gallery which is equal to Gallery_Name_1. but also it can be Gallery_Name_2.

Now, I need it so that the page echos out the TEST 1 bits by using the gallery URL string as a type of prefix. But i'm confussed how to add a string inside another string.

At the moment I've tried

<? echo "$".$gallery."_NameDate"; ?>
But that just outputs
$Gallery_Name_1_NameDate.

Which is near, but I dont want it in text, i need it as a string so it takes the $Gallery_Name_1_NameDate string from the config file using an include (which is in the page) and outputs TEST 1 instead of what it is now.

Rather confussing, but pleeeease help me :(

Regards

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 April 2006 - 11:09 PM

Try this:
<?PHP
$Gallery_Name_1_NameDate = "TEST 1";
$Gallery_Name_2_NameDate = "TEST 2";

$gallery = 'Name_1';

$gal = ${'Gallery_'.$gallery.'_NameDate'};
echo $gal;
?>

Ken

#3 XOpa

XOpa
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 April 2006 - 08:31 PM

Thank you so so much, it worked like a charm. :D






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users