--- Scott Fletcher <[EMAIL PROTECTED]> wrote:
> Hi Fellas!
>
> I haven't found a more efficient way to better
> escape the quote
> characters for the javascript right from PHP because
> I only get "The kid" in
> the javascript alert message, so I'm wondering if
> anyone of you know of
> something better than that...
>
> --snip--
> <form name="Test_Form">
> <?
> $test1 = "The kid's name is \"Bob!\"";
> $test1 = addslashes($test1);
> echo "<input type='hidden'
> name='htmlTest1' value='".$test1."'>";
> echo "<script type='text/javascript'>";
> echo "
> alert(document.Test_Form.htmlTest1.value);";
> echo "</script>";
> ?>
> </form>
> --snip--
I'm a fan of dropping out of PHP to output static
html/js etc. This is especially good practice when you
have large blocks of html/etc.
i.e.
<form name="Test_Form">
<?
$test1 = "The kid's name is \"Bob!\"";
$test1 = addslashes($test1);
?>
<input type='hidden' name='htmlTest1'
value='<?=$test1?>'>
<script type='text/javascript'>
alert(document.Test_Form.htmlTest1.value);
</script>
</form>
I prefer using single quotes when assign string
values. PHP doesn't have to evaluate inside single
quotes.
It's much easier to edit/add/read html code that's not
polluted with escaped quotes
Syntax highlighting makes it easier to spot
"variables"
$bob_age = time() - $birthday_timestamp;
$test1 = 'The kid's name is "Bob!"';
$test2 = 'He is '.$bob_age.' seconds old';
olinux
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php