PHP只获取html代码的一部分

PHP只获取html代码的一部分,php,html,Php,Html,我在codeplex上的项目站点上有文档,我想创建一个PHP代码,将其嵌入到我的站点中。和 如果你能帮助我,那就太好了 这是我想从中提取的代码: 文档 欢迎使用MXSPLI文档 在这里,您可以学习如何使用MXSPLI,以及如何为其创建库 您可以在PHP中使用DOMDocument <?php $pageHtml = file_get_contents('https://mxspli.codeplex.com/documentation'); $document = new DOM

我在codeplex上的项目站点上有文档,我想创建一个PHP代码,将其嵌入到我的站点中。和 如果你能帮助我,那就太好了

这是我想从中提取的代码:


文档
欢迎使用MXSPLI文档

在这里,您可以学习如何使用MXSPLI,以及如何为其创建库


您可以在PHP中使用
DOMDocument

<?php
$pageHtml = file_get_contents('https://mxspli.codeplex.com/documentation');
$document = new DOMDocument();
@$document->loadHtml($pageHtml);

/* Write out the HTML snippet */
echo $document->saveHTML($document->getElementById('WikiContent'));

STRPO将找到字符串的位置

$string = file_get_contents('https://mxspli.codeplex.com/documentation');
$pos = strpos($string,'<div id="WikiContent" class="WikiContent">');
$pos2 = strpos($string, "<div></div>", $pos);
$newstring = substr($string, $pos, ($pos2-$pos));
Echo $newstring;
$string=file\u get\u contents('https://mxspli.codeplex.com/documentation');
$pos=strpos($string',);
$pos2=strpos($string,“,$pos);
$newstring=substr($string,$pos,($pos2-$pos));
Echo$newstring;
编辑:我刚注意到你想要html标签?如果您不想要标签,请查看我的第一个版本的答案。
EDIT2:很抱歉,我测试它时它不起作用,但现在它起作用了。

感谢您发布此邮件。我们又来了@佩德罗洛比托对不起??正则表达式在哪里???@PedroLobito Strpos不是正则表达式,请阅读手册@Andreas done,1+用于
strpos
!当然,正确的方法是使用html解析器,如
DOMDocument
;)我已经测试了你的代码,但它不起作用,我得到
警告:DOMDocument::saveHTML()只需要0个参数,1个在/home/…
中给出,没有任何进一步的数据。@pedrobito你使用的是过时的PHP版本。这将适用于PHP5.3.6或更高版本。
$string = file_get_contents('https://mxspli.codeplex.com/documentation');
$pos = strpos($string,'<div id="WikiContent" class="WikiContent">');
$pos2 = strpos($string, "<div></div>", $pos);
$newstring = substr($string, $pos, ($pos2-$pos));
Echo $newstring;