View Full Version : quotation in echo
Jesper Møller
06-17-2006, 05:17 AM
Im making my first small PHP script, wher i have to use quotations in some echo funktion but how do i do it
like this one > echo "link["$id"]=$count;\n";
Shud i use " or " around the $id
And do i simply put it in like ["$id"] or ?
:confused:
vinyl-junkie
06-17-2006, 06:45 AM
You can use single quotes inside double quotes, or vice versa. It is customary though to use the first option:
echo "link['$id']=$count;\n";
Jesper Møller
06-17-2006, 12:58 PM
Thanks ... But every place i read, it say i shud use double quotations in the script ... so It looks like this
link["test1"]=0
So your saying i shall do it like this
> echo 'link["$id"]=$count;\n';
???
vinyl-junkie
06-17-2006, 04:47 PM
It doesn't matter. Either way is correct syntax. Just do it whichever way makes the most sense to you.
Variables inside single-quotes won't be parsed though, so either:
$id='test1';
$count=0;
echo "link['$id']=$count";
//link['test1']=0
or
$id='test1';
$count=0;
echo 'link["'.$id.'"]=$count';
//link["test1"]=0
Jesper Møller
06-17-2006, 05:21 PM
:) Thank you :)
Jesper Møller
06-18-2006, 06:01 PM
When i change it to
echo*'link["'.$id.'"]=$count';
I get a error
Ellegal character
And it ends op looking like this link["tutorials"]=$count;\nlink["centerpage1"]=$count;\n
:confused:
is the * a typo in the post, or actually in your code?
if the latter, then what are you trying to do with it? (pointers??)
Jesper Møller
06-18-2006, 06:40 PM
Sorry * is a typo :p
echo'link["'.$id.'"]=$count';
Jesper Møller
06-18-2006, 06:41 PM
But think i found out myself :)
echo 'link["' . $id . '"]=' . $count . ';'\n;
Dos that look right :rolleyes:
without the \n yeah, what sort of editor are you using that copies them as text? :|
In my post I took the $id out of the quotes, but completely missed/forgot $count.
Jesper Møller
06-18-2006, 07:39 PM
>"In my post I took the $id out of the quotes, but completely missed/forgot $count."
That i figured out ;)
>"without the \n yeah, what sort of editor are you using that copies them as text?"
Well i use GoLive .. But its not GoLive that puts them ther..
Its the first time im trying to make a PHP script, so i have lookd at other script to find out how to make it.
I have found a small hit counter script, that works ok, but it cant display the hits or the total hits of multiple pages, so im trying to make my own script to do that. The script that counts the hit (and other scripts frome the same place) use this
// What type of server is your website on?
// 1 = UNIX (Linux), 2 = Windows, 3 = Machintos
$settings['system']=1;
if($settings['system'] == 2) {$settings['newline']="\r\n";}
elseif($settings['system'] == 3) {$settings['newline']="\r";}
else {$settings['newline']="\n";}
echo "extcount_link[$id]=$count;\n";
so i thougt it shud bee ther :confused:
Jesper Møller
06-19-2006, 12:14 PM
Got it to work :)
I used
echo "pcount[\"" . $filename . "\"]=" . $filedata . ";\n";
with ' it simply print what is in the ' '
With " it make \n to a line break
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.