File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+ namespace PHPHtmlParser ;
3+
4+ class Curl implements CurlInterface {
5+
6+ /**
7+ * A simple curl implementation to get the content of the url.
8+ *
9+ * @param string $url
10+ * @return string
11+ * @throws Exception
12+ */
13+ public function get ($ url )
14+ {
15+ $ ch = curl_init ($ url );
16+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , true );
17+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
18+ curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 5 );
19+
20+ $ content = curl_exec ($ ch );
21+ if ($ content === false )
22+ {
23+ // there was a problem
24+ $ error = curl_error ($ ch );
25+ throw new Exception ('Error retrieving " ' .$ url .'" ( ' .$ error .') ' );
26+ }
27+
28+ return $ content ;
29+ }
30+ }
Original file line number Diff line number Diff line change 1+ <?php
2+ namespace PHPHtmlParser ;
3+
4+ interface CurlInterface {
5+
6+ /**
7+ * This method should return the content of the url in a string
8+ *
9+ * @param string $url
10+ * @return string
11+ */
12+ public function get ($ url );
13+ }
You can’t perform that action at this time.
0 commit comments