PHP Echo-转义引号 [英] PHP Echo - Escaping quotes

查看:138
本文介绍了PHP Echo-转义引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用PHP编程,但是由于我是新手,所以陷入了困境。

I was programming something in PHP but since I'm a newbie I got stuck.

我不知道如何在下一行转义引号。而且,我认为echo中的PHP标记不正确。我应该如何更改才能使其正常工作?

I have no clue how should I escape quotes on the following line. Moreover, I think the PHP tags inside echo are incorrect. How should I change this to make it work?

echo '<tr onclick="DoNav('list.php?id=<? echo(".$row['ID']."); ?>');">';

提前谢谢! :)

推荐答案

使用反斜杠转义,请使用。

Escape with a backslash, use "." for concatenation.

$row = array();
$row['ID'] = 1;

echo '<tr onclick="DoNav(\'list.php?id=' . $row['ID']. '\');">';

输出

<tr onclick="DoNav('list.php?id=1');">

还请确保转义要在Javascript或HTML中使用的所有内容。对于ID,您可以将其转换为整数:

Also make sure to escape any content you're going to use in Javascript or HTML. For an ID, you might just cast as an integer:

echo '<tr onclick="DoNav(\'list.php?id=' . (int)$row['ID']. '\');">';

字符串逃逸将更为重要。

Strings'll be more important to escape.

这篇关于PHP Echo-转义引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆