We help IT Professionals succeed at work.

Parsing incoming data in while stament...

St_Aug_Beach_Bum
on
210 Views
Last Modified: 2008-04-24
I have an inc file coming in that has something like:

Gina_ad_1="sample text ad 1";
Gina_ad_2="sample of text ad 2";
Gina_ad_3="this is text ad 3";
  //  32 in all

Now I want to display those ads one after another.

I could go:

echo Gina_ad_1;
echo Gina_ad_2:  //etc

but that seems rather ineffecient.... and I also have other users, so, somehow I need something that will, in effect, do this:

$user='Gina';

$i=1;
while ($i<=32) {
echo "$".$user."_ad_".$i."\n";
$i++;
}

but that doesn't parse as I intended it to, it just gives me:

$Gina_ad_1
$Gina_ad_2
$Gina_ad_3

Can you help?   Thanks,   Chris  (using php4.3.3)
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2004
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:

Thank you Zyloch.

I will read up on this eval thing.

In the meantime, I tried solution 2 and it works well.  

The only thing I can't quite figure out (I'm still playing with it) is how to make a new line after each echo $$var

Author

Commented:
Oh, I got it.  The first time I tried maybe the file didn't save or something, didn't work when I put the "\n" in, but now it does.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.