大约 10 年前离开编程领域后,我正在尝试使用 Codeigniter 4。 我的问题是从 XML 文件获取数组。 所以我正在考虑使用 PHP 的 SimpleXMLElement 但我无法访问这个类,因为它正在错误的路径中搜索。 这是我的代码示例:
<?php namespace App\Controllers;
class Helloworld extends BaseController
{
public function index()
{
$xmlstr = '<libri>
<libro>
<autore>J.K.Rowlings</autore>
<titolo>Harry Potter e la pietra filosofale</titolo>
<editore>Salani</editore>
</libro>
<libro>
<autore>J.R.Tolkien</autore>
<titolo>Il signore degli Anelli</titolo>
<editore>Bonpiani</editore>
</libro>
</libri>';
$xml = new SimpleXMLElement($xmlstr);
}
}
这是我得到的错误:
找不到类“App\Controllers\SimpleXMLElement”
有人可以帮助我吗?
最佳答案
就用这个
new \SimpleXMLElement($xmlstr);
在 SimpleXMLElement
之前添加一个反斜杠
关于php - Codeigniter 4 和 SimpleXMLElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65979339/