当使用 http://gmail.com/cb/send/send.php?user_name=admin1&password=test123&subscriber_no=1830070547&mask=Peter&sms= 等参数命中 url 时,我想发送一个 xml 响应'测试短信'
当一个人点击这个链接时,会给出一个喜欢的响应
public function sendResponse($type,$cause) {
$response = '<?xml version="1.0" encoding="utf-8"?>';
$response = $response.'<response><status>'.$type.'</status>';
$response = $response.'<remarks>'.$cause.'</remarks></response>';
return $response;
}
我正在从我的 Controller 文件中调用此方法并仅回显该值。 击球手会得到这个回应吗?
<?php
......
......
echo $sendResponse($type,$cause);
?>
这个回显会不会引起用户的共鸣?
最佳答案
return
本身不会向客户端发送任何内容。如果您回显 sendResponse()
的结果,那么是的,客户端将收到 XML:
echo sendResponse($type,$cause);
请注意,我从 sendResponse 调用中删除了 $
- 如果您使用 $
,PHP 将假定它是一个变量。
建议添加一个 header 来告诉客户端正在发送 XML 和编码,但这对于 XML 的传输不是必需的:
header("Content-type: text/xml; charset=utf-8");
您可以在声明 XML header 后使用连接字符 .
:
public function sendResponse($type,$cause) {
$response = '<?xml version="1.0" encoding="utf-8"?>';
$response .= '<response><status>'.$type.'</status>';
$response = $response.'<remarks>'.$cause.'</remarks></response>';
return $response;
}
....
....
header("Content-type: text/xml; charset=utf-8");
echo sendResponse($type,$cause);
关于php - 在 php 中点击 url 时发送 xml 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13471014/