From b812c09fb2ea9136c8d8754c8b46c55e15162b72 Mon Sep 17 00:00:00 2001 From: Daniel Bigenius Date: Fri, 26 Feb 2016 10:32:42 +0100 Subject: [PATCH 1/2] Added support for proxy --- README.md | 16 ++++++++++++++++ src/Yangqi/Htmldom/Htmldom.php | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5160473..2670406 100644 --- a/README.md +++ b/README.md @@ -50,5 +50,21 @@ foreach($html->find('a') as $element) echo $element->href . '
'; ``` +## Using a proxy + +```php +$auth = base64_encode('proxy_user:pxosy_password'); +$context = array +( + 'http' => array + ( + 'proxy' => 'my.proxy.com:8080', + 'request_fulluri' => true, + 'header' => "Proxy-Authorization: Basic $auth", + ), +); +$context = stream_context_create($context); +$html = new Htmldom($url, true, true, 'UTF-8', true, "\r\n", " ", $context ); +``` See the detailed documentation http://simplehtmldom.sourceforge.net/manual.htm diff --git a/src/Yangqi/Htmldom/Htmldom.php b/src/Yangqi/Htmldom/Htmldom.php index 10a375e..473d4e8 100644 --- a/src/Yangqi/Htmldom/Htmldom.php +++ b/src/Yangqi/Htmldom/Htmldom.php @@ -109,13 +109,17 @@ class Htmldom { 'option'=>array('option'=>1), ); - public function __construct($str=null, $lowercase=true, $forceTagsClosed=true, $target_charset=DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT) + public function __construct($str=null, $lowercase=true, $forceTagsClosed=true, $target_charset=DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT, $context = false) { if ($str) { if (preg_match("/^(http|https):\/\//i",$str) || is_file($str)) { - $this->load_file($str); + if($context) { + $this->load_file($str, false, $context); + } else { + $this->load_file($str); + } } else { From 678ef62ff425b4088a29edc618a725bf172fa502 Mon Sep 17 00:00:00 2001 From: Daniel Bigenius Date: Fri, 26 Feb 2016 10:40:04 +0100 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2670406..dcef3a5 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ foreach($html->find('a') as $element) ## Using a proxy ```php -$auth = base64_encode('proxy_user:pxosy_password'); +$auth = base64_encode('proxy_user:proxy_password'); $context = array ( 'http' => array