function Alert($str)
{
echo("<script language='javascript'>");
echo("alert('$str');");
echo("</script>");
}
//no error
$str="Hello peter";
Alert($str);
//error
$str="Hello peter's cats";
Alert($str);
error code is: Expected ';'
I guess problem is the ' in $str, which makes actural look in second line of fuction Alert() as:
"alert('Hello peter's cats');"
so quote perter's stops (ends) first quote alert('
is that true?
how do u solve this kind problem?
string concept: is this for php?
Moderator: General Moderators
-
php12342005
- Forum Commoner
- Posts: 79
- Joined: Mon Mar 21, 2005 3:35 am
You are missing a pair of quotes around your message string in the alert function... Here is how i tackle this problem usually 
Code: Select all
<?php
$str = addslashes("Hello peter's cats");
echo "<script type='text/javascript'>";
echo "alert('$str')";
echo "</script>";
?>-
php12342005
- Forum Commoner
- Posts: 79
- Joined: Mon Mar 21, 2005 3:35 am