突然我的网站显示新警告 -
相关代码:
printf ("<input type='text' name='C_Comment' value='" . $myComment . "' >");
Run Code Online (Sandbox Code Playgroud)
我得到的警告:
可能是因为$ myComment为null.
我知道我可以修复它,如果我第一次测试该值是否为null,然后才能对它进行补充.但有更简单的方法吗?
为什么我之前没有得到这个警告?
谢谢,
Atara
编辑:抱歉,错误的标题.问题是$ myComment不是NULL,它包含特殊字符.
不,你得到那个警告,因为你没有提供足够的论据printf; 可能$myComment包含了printf占位符%s.
使用echo,如果你不希望使用替代printf的格式.您也可以重写您的printf电话:
printf ("<input type='text' name='C_Comment' value='%s'>",
$myComment);
Run Code Online (Sandbox Code Playgroud)
确保你已经逃过了特殊的角色$myComment(参见参考资料htmlspecialchars).