开发者

Javascript function argument error

开发者 https://www.devze.com 2023-02-03 19:36 出处:网络
I\'m using the following function: <body onload=\"testing(<?php print \"\'\". $_SESSION[\'data\'] . \"\'\"; ?>);\">

I'm using the following function:

<body onload="testing(<?php print "'". $_SESSION['data'] . "'"; ?>);">

if $_SESSION['data'] = "My name is function" then it works fine but

if $_SESSION['data'] = "Calling jackson's function" then it gives error.

Can you tell me how can i pass an argument which may contain characters like

$_SESSION['data'] = "Calling jackson's function"

into the testing functi开发者_开发百科on parameters.


Escape them with addslashes()

echo "'" . addslashes($_SESSION['data']) . "'";


You could do:

<body onload="testing(<?php print "'". addslashes($_SESSION['data']) . "'"; ?>);">
0

精彩评论

暂无评论...
验证码 换一张
取 消