comparison common-functions.inc @ 93:8aadd7a23b68

Moved some functionality from common-functions into Http class. Reorganized Validator into a class hierarchy. Added functionality for validating with a buffer in addition to URLs.
author Tom Fredrik "BFG" Klaussen <bfg@blenning.no>
date Thu, 18 Oct 2012 16:44:48 +0200
parents aafc23919e79
children 2370f4450983
comparison
equal deleted inserted replaced
92:f468365813c9 93:8aadd7a23b68
213 $l = strlen($haystack) - strlen($needle); 213 $l = strlen($haystack) - strlen($needle);
214 return strrpos($haystack, $needle) === $l; 214 return strrpos($haystack, $needle) === $l;
215 } 215 }
216 216
217 /** 217 /**
218 * Queries a URL for headers
219 *
220 * @param $url the url to query
221 * @return an associative array of all headers returned
222 */
223 function getHeaders($url, $timeout = 1)
224 {
225 $response = @http_head($url, array("timeout" => $timeout), $info);
226
227 if (array_key_exists('error', $info) && $info['error']) {
228 throw new RequestException($info);
229 }
230
231 $headers = array();
232 $response = trim($response);
233 $str = explode("\n", $response);
234 $headers[''] = trim($str[0]);
235 foreach($str as $kv) {
236 $p = strpos($kv, ":");
237 if ($p) {
238 $key = substr($kv, 0, $p);
239 $value = trim(substr($kv, $p + 1));
240 $headers[$key] = $value;
241 }
242 }
243 return $headers;
244 }
245
246 /**
247 * Generates the query part of an URI 218 * Generates the query part of an URI
248 * 219 *
249 * @param $opts an associative array of options 220 * @param $opts an associative array of options
250 * @return a string that can be used for the query part of an URI 221 * @return a string that can be used for the query part of an URI
251 */ 222 */