Page 1 of 1

A really simple question.

Posted: Wed Feb 22, 2006 12:00 am
by JellyFish
I need to solve this problem of mine. How I'll do this is I'll ask one question.

How do I make a var .= a value but also have it equal ", " with it. Example:

Code: Select all

$var .= "bla bla bla ", " ";
and then I want it to look like this when echoed:
bla bla bla", "
It seems to be vary simple. Might be some way to do this that I don't know how to.

Thanks and all help is appreciated.

Posted: Wed Feb 22, 2006 12:03 am
by Christopher
Either with double quotes (which allows you to embed variables):

Code: Select all

$var .= "bla bla bla "\, \" $name";
or single quotes:

Code: Select all

$var .= 'bla bla bla ", " ' . $name;

Posted: Wed Feb 22, 2006 12:10 am
by JellyFish
Thanks man. But it doesn't seem to work to well. this is my full statement.

Code: Select all

$array_block .= '<img src='http://www..com/icons/$icon' width=100 height=100 border=0> ", " ';
I'm getting an error:
Parse error: parse error, unexpected T_STRING in /home//html/index.php on line 24

Posted: Wed Feb 22, 2006 12:20 am
by feyd
notice how the colors of the highlighting changed? Yeah..

Time to read the documentation on strings.

Posted: Wed Feb 22, 2006 12:33 am
by JellyFish
I know the problem here.

Code: Select all

$array_block .= '<img src='http://www..com/icons/$icon' width=100 height=100 border=0> ", " ';   
                           ^                           ^
Because of the single quotes at the begining of the specified value.

Code: Select all

$array_block .= '<img src='http://www..com/icons/$icon' width=100 height=100 border=0> ", " ';   
                 ^                                                                           ^
But my so what I did was this.

Code: Select all

$array_block .= '<img src=http://www..com/icons/$icon width=100 height=100 border=0>", " ';
It works perfectly fine. But the $icon value in http://www..com/icons/$icon doesn't display it's self instade displays just the $icon not for example say the value of $icon is dude, then instade of displaying dude it just stays as $icon. If this makes sence to you then why is this?

Posted: Wed Feb 22, 2006 12:46 am
by josh

Code: Select all

echo 'o\'reilly' ;
looks like its working...

Posted: Wed Feb 22, 2006 12:51 am
by JellyFish
It doesn't seem to be on my side. Please help me.

What it seems to be doing and this is what I have:

Code: Select all

$array_block .= '<img src=\'http://www..com/icons/$icon\' width=100 height=100 border=0>", " ';
It seems, and I'm going to have to repeat myself, that $icon isn't reterning the value of dude, but just returning the value of $icon. If I where to look at my souce code, it'll look like this:
<img src='http://www..com/icons/$icon' width=100 height=100 border=0>", "

Posted: Wed Feb 22, 2006 12:53 am
by josh
What's the error you're getting?

Posted: Wed Feb 22, 2006 12:54 am
by feyd
your "simple questions" although normally are simple to answer never turn out that way No0b.

Posted: Wed Feb 22, 2006 1:00 am
by JellyFish
Is it just me or does it seem like someone as some sorta grudge agiants me?

I not getting any error. My problem is is that my picture that is supposed to be displayed, is not. Cause the source is http://www..com/icons/$icon not http://www..com/icon/dude.

And maybe the fact that I didn't mention that the $array_block var is being displayed in an array in JS.

Code: Select all

descarray = new Array(
"<? echo $array_block; ?>"
);

Posted: Wed Feb 22, 2006 1:10 am
by Christopher
You really need to read the Strings page in the PHP manual and experiment with different combinations:

Code: Select all

$icon = 'dude';

echo 'Hello $icon';
// Outputs: Hello $icon

echo "Hello $icon";
// Outputs: Hello dude

echo 'Hello ' . $icon
// or
echo "Hello " . $icon
// Outputs: Hello dude

Posted: Wed Feb 22, 2006 1:20 am
by JellyFish
Ok finally I got it. But it I defenetly wouldn't of if it wheren't for you guys. Thanks you guys. This is something that I've been trying to figure out for a long time now. Thanks.

Posted: Wed Feb 22, 2006 10:34 am
by shiznatix
just remember that variables will be echoed out as what they are equal to when in double quotes but this will not happen in single quotes. it is generally the easiest to do it like:

Code: Select all

$var = 'explode';
echo '<a href="www.website.com?var='.$var.'">look here</a>';
because if you use a editor with color coding (which you should) you will be able to see that you have a variable there, otherwise it can be hard to spot.