i'm doing a project in php! the problem is array is not printing properly. Actually im trying to retrieve text data from mysql using php. im able to retrieve the data, but while im printing in the document it is not printing as i want!!
我正在用PHP做一个项目!问题是数组打印不正确。实际上我试图使用PHP从mysql检索文本数据。我能够检索数据,但在文档中打印时,它不是我想要的打印!
echo "<td><p onclick=alert('".$arr[$t]."'); ><u>VIEW</u></p></td>";
$arr[$t] is text data i retrieved from database. it should print like this(assuming $arr[$t] has data "this is a paragraph")
but the actual output is like this..
output in CHROME
$ arr [$ t]是我从数据库中检索的文本数据。它应该这样打印(假设$ arr [$ t]有数据“这是一个段落”)但实际输出就像这样..输出在CHROME
<td><p onclick="alert('this" is a paragraph'); ><u>VIEW</u></p></td>
output in FIREFOX
FIREFOX中的输出
<td><p paragraph');="" a="" is="" onclick="alert('this" ><u>VIEW</u></p></td>
i dont know why it's happening.
please help me out with this..
thanks in advance :)
我不知道为什么会这样。请帮我解决这个问题..在此先感谢:)
1 个解决方案
#1
1
The syntax highlighting from your chrome output gives it away - you have a double quote nested inside your double quotes, which is invalid HTML.
从您的chrome输出中突出显示的语法将其删除 - 您的双引号内嵌有双引号,这是无效的HTML。
You should escape all output before rendering it, using something like htmlspecialchars (http://au2.php.net/manual/en/function.htmlspecialchars.php).
您应该在渲染之前使用htmlspecialchars(http://au2.php.net/manual/en/function.htmlspecialchars.php)之类的内容来转义所有输出。
Also, you should wrap your onclick handler in quotes - eg. onlick="alert('stuff stuff more stuff')"
or it won't parse correctly.
此外,您应该将onclick处理程序包装在引号中 - 例如。 onlick =“alert('东西更多的东西')”或它不会正确解析。
#1
1
The syntax highlighting from your chrome output gives it away - you have a double quote nested inside your double quotes, which is invalid HTML.
从您的chrome输出中突出显示的语法将其删除 - 您的双引号内嵌有双引号,这是无效的HTML。
You should escape all output before rendering it, using something like htmlspecialchars (http://au2.php.net/manual/en/function.htmlspecialchars.php).
您应该在渲染之前使用htmlspecialchars(http://au2.php.net/manual/en/function.htmlspecialchars.php)之类的内容来转义所有输出。
Also, you should wrap your onclick handler in quotes - eg. onlick="alert('stuff stuff more stuff')"
or it won't parse correctly.
此外,您应该将onclick处理程序包装在引号中 - 例如。 onlick =“alert('东西更多的东西')”或它不会正确解析。