help me to fix the newbie problem: double quotes in echo
Posted: Thu Jul 28, 2005 1:33 pm
I am a C++ programmer and move to php temprately now.
I use braces for echo: echo(), and double quotes for string in possible cases, otherwise I just feel unconfortable.
my purpose is to display a message box in php code.
ok, following is my sick code:
function MsgBox000($str)
{
echo("<script language='javascript'>"); //line 1
second line: discussed in bellow.
echo("</script>"); //line 3
}
(line 1 and 3 are easy)
line 2:
//works but use single quote: echo('...');
echo('alert("'.$str.'");');
now I want to modify single quote to double quote: echo("...");
but got all errors with these 3 tests:
1) echo("alert("$str");");
2) echo("'alert("'.$str.'");'");
3) echo("alert("".$str."");");
(and more tests, I don't want to list all)
do you know correct syntax for echo("...") of alert()?
thanks
I use braces for echo: echo(), and double quotes for string in possible cases, otherwise I just feel unconfortable.
my purpose is to display a message box in php code.
ok, following is my sick code:
function MsgBox000($str)
{
echo("<script language='javascript'>"); //line 1
second line: discussed in bellow.
echo("</script>"); //line 3
}
(line 1 and 3 are easy)
line 2:
//works but use single quote: echo('...');
echo('alert("'.$str.'");');
now I want to modify single quote to double quote: echo("...");
but got all errors with these 3 tests:
1) echo("alert("$str");");
2) echo("'alert("'.$str.'");'");
3) echo("alert("".$str."");");
(and more tests, I don't want to list all)
do you know correct syntax for echo("...") of alert()?
thanks