私のディレクトリにxmlファイルを作成しました。私はこのファイルをブラウザでPHPを使って表示したいのですか?Php Laravel - xmlファイルをブラウザに表示するには
(私は、サイトマップなどということを示したい)
ここでは私のコードです: :ここ
<?xml version="1.0"?>
<template><bla>blub</bla><foo>bar</foo><another_array><stack>overflow</stack></another_array></template>
が結果です:
public function siteMap()
{
$test_array = array (
'bla' => 'blub',
'foo' => 'bar',
'another_array' => array (
'stack' => 'overflow',
),
);
$xml_template_info = new \SimpleXMLElement("<?xml version=\"1.0\"?><template></template>");
$this->array_to_xml($test_array,$xml_template_info);
$xml_template_info->asXML(dirname(__FILE__)."/sitemap.xml") ;
header('Content-type: text/xml');
dd(readfile(dirname(__FILE__)."/sitemap.xml"));
}
public function array_to_xml(array $arr, \SimpleXMLElement $xml)
{
foreach ($arr as $k => $v) {
is_array($v)
? $this->array_to_xml($v, $xml->addChild($k))
: $xml->addChild($k, $v);
}
return $xml;
}
私はブラウザにこのxmlファイルを表示したい、これを正しく行うためのアイデアはありますか?
EDITED:ヘッダー( 'Content-type:text/plain');
これはいくつかの追加のレポートで構成されています。
を試してみてください –
私は 'header( 'Content-type:text/plain');がうまくいくと思います! –
@ Alok私は私の質問に追加しました。 – AFN