-1

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>

2 Answers2

1

You can use DOMDocument in PHP.

<?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'));
Candy Gumdrop
  • 2,745
  • 1
  • 14
  • 16
  • I've tested your code and it doesn't work, I get `Warning: DOMDocument::saveHTML() expects exactly 0 parameters, 1 given in /home/...` without any further data. – Pedro Lobito Apr 29 '16 at 15:05
  • 1
    @PedroLobito You are using an outdated version of PHP. This will work with PHP 5.3.6 or greater. – Candy Gumdrop Apr 29 '16 at 15:16
1

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.
...

Andreas
  • 23,610
  • 6
  • 30
  • 62