Mihail Mojsoski Mihail Mojsoski - 7 months ago 15
PHP Question

PHP get only one section of the html code

I have documentation on my project site on codeplex, and i want to create a PHP code to embed it to my site. and
this is the part of code i want to get from the page.
If you could help me it would be great.

This is the code i want to extract from https://mxspli.codeplex.com/documentation:

<div id="WikiContent" class="WikiContent">

<div class="wikidoc">
<h1><img src="https://download-codeplex.sec.s-msft.com/Download?ProjectName=mxspli&amp;DownloadId=1564842&amp;Build=21031" alt="" width="101" height="23">&nbsp;Documentation</h1>
<p>Welcome to MXSPLI Documentation</p>
<p>Here you can learn how to use MXSPLI, and how to make libraries for it.</p>
<ul>
<li><a href="https://mxspli.codeplex.com/wikipage?title=Tutorials">Tutorials</a> </li><li><a href="https://mxspli.codeplex.com/wikipage?title=Released%20Libraries">Released Libraries</a>
</li><li><a href="https://mxspli.codeplex.com/wikipage?title=Main%20Functions">Main Functions</a>
</li></ul>
</div>
<div></div>
</div>

Answer

Strpos will find the position of the string

$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;

Edit: I just noticed you wanted the html tags? If you don't want the tags check my first version of this answer.
EDIT2: sorry it didn't work when I tested it, but now it does.
...