根据文件,我不应该有魔术引号,但我这样做。我正在建立一个苗条框架的网站。我正在尝试为我的RSS Feed创建一个xml创建者,api调用看起来像这样:
function createRSS($dbh, $args) {
$xml = "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
$xml = $xml."<rss version=\"2.0\">\n";
$xml = $xml."\t<channel>\n";
$xml = $xml."\t\t<title>".$args['title']."</title>\n";
$xml = $xml."\t\t<link>".$args['link']."</link>\n";
$xml = $xml."\t\t<image>\n";
$xml = $xml."\t\t\t<url>".$args['imageURL']."</url>\n";
$xml = $xml."\t\t\t<title>".$args['imageTitle']."</title>\n";
$xml = $xml."\t\t\t<link>".$args['link']."</link>\n";
$xml = $xml."\t\t</image>\n";
$xml = $xml."\t\t<description>".$args['description']."</description>\n";
$xml = $xml."\t\t<language>".$args['language']."</language>\n";
$xml = $xml."\t\t<category>".$args['category']."</category>\n";
$xml = $xml."\t\t<copyright>".$args['copyright']."</copyright>\n";
$xml = $xml."\t\t<lastBuildDate>".$args['lastBuildDate']."</lastBuildDate>\n";
$xml = $xml."\t\t<ttl>".$args['ttl']."</ttl>\n";
$xml = $xml."\t</channel>\n";
$xml = $xml."</rss>\n";
try {
$xml = simplexml_load_string($xml);
$result['xmlString'] = print_r($xml);
$result['args'] = $args;
$file_path = stripslashes("/_rss/_profile/_".$args['profile']."/rss_".$args['profile'].".xml");
$result['xmlLink'] = $file_path;
$result['test'] = '/hey/there';
return $result;
}
catch (Exception $e) {
$result['error'] = "1";
$result['message'] = $e->getMessage();
return $result;
}
}
$app->post('/api/createRSS', function() use ($dbh) {
$args['user'] = $_POST['user'];
$args['title'] = $_POST['title'];
$args['link'] = $_POST['link'];
$args['description'] = $_POST['description'];
$args['language'] = "en-us";
$args['copyright'] = $_POST['copyright'];
$args['creationDate'] = "11/03/1993";
$args['ttl'] = "340";
$args['imageURL'] = $_POST['imageURL'];
$args['imageTitle'] = $_POST['imageTitle'];
$args['category'] = $_POST['title'];
echo print_r($args);
echo json_encode(createRSS($dbh, $args));
});
api调用的输出如下所示:
Array
(
[user] => 1
[title] => 2
[link] => 3
[description] => 4
[language] => en-us
[copyright] => 5
[creationDate] => 11/03/1993
[ttl] => 340
[imageURL] =>
[imageTitle] => 8
[category] => 2
)
1SimpleXMLElement Object
(
[@attributes] => Array
(
[version] => 2.0
)
[channel] => SimpleXMLElement Object
(
[title] => 2
[link] => 3
[image] => SimpleXMLElement Object
(
[url] => SimpleXMLElement Object
(
)
[title] => 8
[link] => 3
)
[description] => 4
[language] => en-us
[category] => 2
[copyright] => 5
[lastBuildDate] => SimpleXMLElement Object
(
)
[ttl] => 340
)
)
{"xmlString":true,"args":
{"user":"1","title":"2","link":"3","description":"4",
"language":"en-us","copyright":"5","creationDate":"11\/03\/1993",
"ttl":"340","imageURL":null,"imageTitle":"8","category":"2"},
"xmlLink":"\/_rss\/_profile\/_\/rss_.xml","test":"\/hey\/there"}
最大的问题是我在xmlLink中的链接有添加的反斜杠,它不会让我导航到正确的文件。我打印了phpInfo响应,它看起来像:
PHP Version 5.5.9-1ubuntu4.14
我不知道发生了什么,每个人都说这不应该是5.5中的问题。感谢。