PHP:如何将NULL连接到字符串

Ata*_*ara 0 php string printf

突然我的网站显示新警告 -

相关代码:

printf ("<input type='text' name='C_Comment' value='" . $myComment . "'  >");
Run Code Online (Sandbox Code Playgroud)

我得到的警告:

  • 警告:printf()function.printf:参数太少

可能是因为$ myComment为null.

  1. 我知道我可以修复它,如果我第一次测试该值是否为null,然后才能对它进行补充.但有更简单的方法吗?

  2. 为什么我之前没有得到这个警告?

谢谢,

Atara

编辑:抱歉,错误的标题.问题是$ myComment不是NULL,它包含特殊字符.

Art*_*cto 6

不,你得到那个警告,因为你没有提供足够的论据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).