Skip to content
This repository has been archived by the owner on Mar 26, 2022. It is now read-only.

Proxysupport #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,21 @@ foreach($html->find('a') as $element)
echo $element->href . '<br>';
```

## Using a proxy

```php
$auth = base64_encode('proxy_user:proxy_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

8 changes: 6 additions & 2 deletions src/Yangqi/Htmldom/Htmldom.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down