开发者

what is the meaning of this statement in PHP

开发者 https://www.devze.com 2023-01-14 20:09 出处:网络
. $row[\'NO\'] = \'开发者_开发问答<a href=\"javascript:void(0)\"onClick=\"openmywindow(\\\'\'.$row[\'bcd\'].\'\\\',\\\'\'.$row[\'gfh\'].\'\\\',\\\'\'.$row[\'test2\'].\'\\\',\\\'\'.$_REQUEST[\'test

.

$row['NO'] = '开发者_开发问答<a href="javascript:void(0)"        onClick="openmywindow(\''.$row['bcd'].'\',\''.$row['gfh'].'\',\''.$row['test2'].'\',\''.$_REQUEST['test1'].'\')">'.$row['abc'].'</a>'

In the above statement, what is the meaning of escaping the values in that manner such as '\'. How can i learn this? In the above statement i want to replace the php variable $row['TEST2'] with a static value 'OPEN', but i am getting a syntax error.


$row['NO'] = '<a href="javascript:void(0)" onClick="openmywindow(\''.$row['bcd'].'\',\''.$row['gfh'].'\',\'OPEN\',\''.$_REQUEST['test1'].'\')">'.$row['abc'].'</a>';

Because the escaping is very confusing it might be better to use HEREDOC:

$row['NO'] =<<<EOC;
<a href="javascript:void(0)" onClick="openmywindow('$row[bcd]','$row[gfh]','OPEN','$_REQUEST[test1].')">$row[abc]</a>
EOC;

More about strings in the manual (including escaping and heredoc).

PS: Do not use $_REQUEST. Instead use $_GET or $_POST (the one that is appropriate here.)


In the above statement what is the meaning of escaping the values in that manner suchas '\'.How can we learn this

Have a look at this tutorial :)

PHP and Escaping

For the error, make sure that you escape the strings correctly.


This is what I would suggest that you do instead of escaping + concatenating strings :

$html = "<a href=\"javascript:void(0);\" onclick=\"openmywindow('%s','%s','%s',%s');\">%s</a>";
$row['NO'] = sprintf($html, 
    $row['bcd'], 
    $row['gfh'],
    $row['test2'],
    $_REQUEST['test1'],
    $row['abc']
);

And then replace whatever you need to replace... Read the manual about sprintf for more details.

Also, if any argument after $html contain ' chars, you must call addslashes on those arguments.

** UPDATE **

About $_REQUEST, read here why it is not recommended to use it.

0

精彩评论

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