PHP语法建议
我有以下代码:PHP语法建议,php,format,Php,Format,我有以下代码: $feed->item([ 'title' => $post->title, 'description|cdata' => $feedy . $post->description, 'link' => URL::to($post->slug), 'pubDate' => $pubDate, 'guid' => $post->title, 'media:text' =>
$feed->item([
'title' => $post->title,
'description|cdata' => $feedy . $post->description,
'link' => URL::to($post->slug),
'pubDate' => $pubDate,
'guid' => $post->title,
'media:text' => $post->title,
'dc:creator' => 'Μιχάλης Γεωργίου'
]);
我想集成这段代码,这是代码文档的一个示例,但我不确定如何集成:
$item['enclosure'] = [
'url'=> $image_url,
'type' => mime_content_type($image_path),
'length' => filesize($image_path)
];
$feed->item($item);
我尝试了以下方法,但无效:
$feed->item([
'title' => $post->title,
'description|cdata' => $feedy . $post->description,
'link' => URL::to($post->slug),
'pubDate' => $pubDate,
'guid' => $post->title,
'media:text' => $post->title,
'dc:creator' => 'Μιχάλης Γεωργίου'
],
$item['enclosure'] = [
'url'=> $image_url,
'type' => mime_content_type($image_path),
'length' => filesize($image_path)
]);
$feed->item($item);
请告知这是否是正确的语法结构,因为Im接收到有关语法的错误:
SimpleXMLElement::addChild()希望参数2是字符串,数组给定
您尝试过这个吗
$feed->item([
'title' => $post->title,
'description|cdata' => $feedy . $post->description,
'link' => URL::to($post->slug),
'pubDate' => $pubDate,
'guid' => $post->title,
'media:text' => $post->title,
'dc:creator' => 'Μιχάλης Γεωργίου',
'enclosure' => [
'url'=> $image_url,
'type' => mime_content_type($image_path),
'length' => filesize($image_path),
]
]);
我认为你的错误不在代码中。请参阅
addChild()
方法属性。是否确实可以将$item
项作为数组?也许您应该使用$item=[…]而不是$item['enclosure']=[…]
。您引用的代码文档示例是什么?以下是我使用的文档和代码:@SerhiiVasko@ttrasn这是我的addChild代码: