I’m trying to find all href links on a webpage and replace the link with my own proxy link.
For example
<a href="http://www.google.com">Google</a>
Needs to be
<a href="http://www.example.com/?loadpage=http://www.google.com">Google</a>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use PHP’s
DomDocumentto parse the pageCheck it out here: http://codepad.org/9enqx3Rv
If you don’t have the HTML as a string, you may use cUrl (docs) to grab the HTML, or you can use the
loadHTMLFilemethod ofDomDocumentDocumentation
DomDocument– http://php.net/manual/en/class.domdocument.phpDomElement– http://www.php.net/manual/en/class.domelement.phpDomElement::getAttribute– http://www.php.net/manual/en/domelement.getattribute.phpDOMElement::setAttribute– http://www.php.net/manual/en/domelement.setattribute.phpurlencode– http://php.net/manual/en/function.urlencode.phpDomDocument::loadHTMLFile– http://www.php.net/manual/en/domdocument.loadhtmlfile.php