Используйте PHP DomDocument
для разбора страницы
$doc = new DOMDocument();
// load the string into the DOM (this is your page's HTML), see below for more info
$doc->loadHTML('Google');
//Loop through each tag in the dom and change the href property
foreach($doc->getElementsByTagName('a') as $anchor) {
$link = $anchor->getAttribute('href');
$link = 'http://www.example.com/?loadpage='.urlencode($link);
$anchor->setAttribute('href', $link);
}
echo $doc->saveHTML();
Проверьте здесь: http://codepad.org/9enqx3Rv
Если у вас нет HTML в виде строки, вы можете использовать cUrl ( docs ), чтобы захватить HTML, или вы можете использовать метод loadHTMLFile
для DomDocument
Документация
DomDocument
- http://php.net/manual/en/class.domdocument.php DomElement
- http://www.php.net/manual/en/class.domelement.php DomElement::getAttribute
- http://www.php.net /manual/en/domelement.getattribute.phpDOMElement::setAttribute
- http://www.php.net/manual/en/domelement.setattribute.php urlencode
- http://php.net/manual/en/function.urlencode.php DomDocument::loadHTMLFile
- http://www.php.net/manual/en/domdocument.loadhtmlfile.php