Php 输出变量值

Php 输出变量值,php,Php,我试图在php中输出变量的字符串值 // sanitizes the string value that's passed in from the sending page $cmessage = filter_var($_POST["confmsg"], FILTER_SANITIZE_STRING); $output = json_encode(array('type'=>'message', 'text' => "<div style='margin-bottom

我试图在php中输出变量的字符串值

 // sanitizes the string value that's passed in from the sending page
 $cmessage = filter_var($_POST["confmsg"], FILTER_SANITIZE_STRING); 
 $output = json_encode(array('type'=>'message', 'text' => "<div style='margin-bottom: 7px; clear:right;'>" . $user_name . ':  </div>echo "$cmessage"'));
//清除从发送页面传入的字符串值
$cmessage=filter\u var($\u POST[“confmsg”],filter\u SANITIZE\u字符串);
$output=json_encode(数组('type'=>'message','text'=>''.$user_name.':echo“$cmessage”);
$output
显示在发送页面的警报中,但它显示为文本。
示例:
Joe:echo$cmessage


我需要做什么才能让
$cmessage
的字符串显示出来?

这是因为你的单引号和双引号都弄乱了,请尝试以下方法:

// sanitizes the string value that's passed in from the sending page
$cmessage = filter_var($_POST["confmsg"], FILTER_SANITIZE_STRING); 
$output = json_encode(array('type'=>'message', 'text' => "<div style='margin-bottom: 7px; clear:right;'>$user_name:</div>$cmessage"));
//清除从发送页面传入的字符串值
$cmessage=filter\u var($\u POST[“confmsg”],filter\u SANITIZE\u字符串);
$output=json_encode(数组('type'=>'message','text'=>“$user_name:$cmessage”);
编辑: 这可能是一个更好的一个对你来说,稍微容易理解

// sanitizes the string value that's passed in from the sending page
$cmessage = filter_var($_POST["confmsg"], FILTER_SANITIZE_STRING); 
$output = json_encode(array('type'=>'message', 'text' => "<div style='margin-bottom: 7px; clear:right;'>".$user_name.":</div>".$cmessage));
//清除从发送页面传入的字符串值
$cmessage=filter\u var($\u POST[“confmsg”],filter\u SANITIZE\u字符串);
$output=json_encode(数组('type'=>'message','text'=>“”.$user_name.:“$cmessage));

如果字符串是由单引号(')创建的,则php字符串不计算变量。请查看:


谢谢,我总是喜欢引用。
// Outputs: Variables do not $expand $either
echo 'Variables do not $expand $either';