Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use PHP's <code>DomDocument</code> to parse the page</p> <pre><code>$doc = new DOMDocument(); // load the string into the DOM (this is your page's HTML), see below for more info $doc-&gt;loadHTML('&lt;a href="http://www.google.com"&gt;Google&lt;/a&gt;'); //Loop through each &lt;a&gt; tag in the dom and change the href property foreach($doc-&gt;getElementsByTagName('a') as $anchor) { $link = $anchor-&gt;getAttribute('href'); $link = 'http://www.example.com/?loadpage='.urlencode($link); $anchor-&gt;setAttribute('href', $link); } echo $doc-&gt;saveHTML(); </code></pre> <p>Check it out here: <a href="http://codepad.org/9enqx3Rv" rel="nofollow">http://codepad.org/9enqx3Rv</a></p> <p>If you don't have the HTML as a string, you may use cUrl (<a href="http://php.net/manual/en/book.curl.php" rel="nofollow">docs</a>) to grab the HTML, or you can use the <code>loadHTMLFile</code> method of <code>DomDocument</code></p> <p><strong>Documentation</strong> </p> <ul> <li><code>DomDocument</code> - <a href="http://php.net/manual/en/class.domdocument.php" rel="nofollow">http://php.net/manual/en/class.domdocument.php</a></li> <li><code>DomElement</code> - <a href="http://www.php.net/manual/en/class.domelement.php" rel="nofollow">http://www.php.net/manual/en/class.domelement.php</a></li> <li><code>DomElement::getAttribute</code> - <a href="http://www.php.net/manual/en/domelement.getattribute.php" rel="nofollow">http://www.php.net/manual/en/domelement.getattribute.php</a></li> <li><code>DOMElement::setAttribute</code> - <a href="http://www.php.net/manual/en/domelement.setattribute.php" rel="nofollow">http://www.php.net/manual/en/domelement.setattribute.php</a></li> <li><code>urlencode</code> - <a href="http://php.net/manual/en/function.urlencode.php" rel="nofollow">http://php.net/manual/en/function.urlencode.php</a></li> <li><code>DomDocument::loadHTMLFile</code> - <a href="http://www.php.net/manual/en/domdocument.loadhtmlfile.php" rel="nofollow">http://www.php.net/manual/en/domdocument.loadhtmlfile.php</a></li> <li>cURL - <a href="http://php.net/manual/en/book.curl.php" rel="nofollow">http://php.net/manual/en/book.curl.php</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload