在下面的代码中,我试图用一些html替换$content中的每个图像.使用$dom-> saveHTML($image)我得到图像html,但str_replace不会替换它.我不知道为什么.$content = '<div class="content"><img src="some-image.png"></div>'; $dom = new DOMDocument; $dom->loadHTML($content); $images = $dom->getElementsByTagName('img'); foreach ($images as $image) {$i = $dom->saveHTML($image);$replacement = '<div class="test"><a href="...
考虑这个例子,test.php:<?php $mystr = "<p>Hello, με ???? ?a ?y je??</p>"; var_dump($mystr); $domdoc = new DOMDocument('1.0', 'utf-8'); //DOMDocument(); $domdoc->loadHTML($mystr); // already here corrupt UTF-8? var_dump($domdoc); ?>如果我用PHP 5.5.9(cli)运行它,我进入终端:$php test.php string(50) "<p>Hello, με ???? ?a ?y je??</p>" object(DOMDocument)#1 (34) {["doctype"]=>string(22) "(object ...
所以我从API中提取xml,我的目标是将xhtml作为html保存在文件中供用户查看. 问题是,保存的html文件得到了一些它不应该有的新怪异实体.这是一个例子. 这就是拉动的xhtml片段的样子:<p> "At that point这是保存的文件的样子:<p>Â Â Â "At that point这就是Chromium看到的:<p>? ? ? "At that point从被拉动的xhtml到被保存的它,它被几个不同的类处理,因此为了简单起见,我将简化数据传递的所有对象.//curl ca...
我试图隐藏用Php单词格式化的HTML. 我用summernote创建了一个html表单. Summernote允许用户格式化文本.此文本使用html标记保存到数据库中. 接下来使用phpWord,我想将捕获的信息输出到word文档中.请参阅以下代码:$rational = DB::table('rationals')->where('qualificationheader_id',$qualId)->value('rational');$wordTest = new \PhpOffice\PhpWord\PhpWord();$newSection = $wordTest->addSection();$newSection->getStyle()->...
我有一个字符串值,我正在尝试提取列表项.我想提取文本和任何子节点,但是,DOMDocument正在将实体转换为角色,而不是保留原始状态. 我已经尝试将DOMDocument :: resolveExternals和DOMDocument :: substituteEntities设置为false,但这没有任何效果.应该注意我使用PHP 5.2.17在Win7上运行. 示例代码是:$example = '<ul><li>text</li>'.'<li>½ of this is <strong>strong</strong></li></ul>';echo 'To be converted:'.PHP_EOL....
我想用PHP和CURL废弃一个中文网站.早些时候我遇到了压缩结果的问题,SO帮助我解决了问题.现在我在通过PHP-DOMDocument解析内容时遇到了麻烦.错误如下,Warning: DOMDocument::loadHTML(): input conversion failed due to input error, bytes 0xE3 0x80 0x90 0xE8 in /var/www/html/ ..即使警告这是阻止进一步的结果. 我的代码如下:$agent = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'; $cu...