PHP fetches all the headers sent by the server in response to a HTTP request


$url = 'http://google.com';
$headers = @get_headers($url, 1);
if ( $headers && is_array($headers) ) {
if ( isset($headers[0]) &&
preg_match('/^HTTP\/\S+\s+([1-9][0-9][0-9])\s+.*/', $headers[0], $matches) ) {
$info['http_code'] = $matches[1];
}
if ( isset($headers['Content-Type']) ) {
if ( is_array($headers['Content-Type']) ) {
$info['content_type'] = $headers['Content-Type'][0];
} else { $info['content_type'] = $headers['Content-Type']; }
}
}
print_r($headers);
echo '<br />';
print_r($headers['Content-Type']);
echo '<br />';
if ( isset($info['http_code']) )
echo "\$info['http_code']" . $info['http_code'] . '<br />';
if ( isset($info['content_type']) )
echo "\$info['content_type']" . $info['content_type'] . '<br />';

PHP strip all HTML tags including script, iframe and style

This differs from strip_tags() because it removes the contents of the <script>, <iframe> and <style> tags.
E.g. strip_tags( '<script>something</script>' ) will return 'something', while this code will return the empty string.


preg_match_all('/<script(.*?)<\/script>/si', $html, $arr);
foreach ($arr[0] as $item) {
if ( ! stripos($item, '<script', 7) ) {
$html = str_replace($item, '', $html);
}
unset($item);
}

preg_match_all('/<iframe(.*?)<\/iframe>/si', $html, $arr);
foreach ($arr[0] as $item) {
if ( ! stripos($item, '<iframe', 7) ) {
$html = str_replace($item, '', $html);
}
unset($item);
}

preg_match_all('/<style(.*?)<\/style>/si', $html, $arr);
foreach ($arr[0] as $item) {
$html = str_replace($item, '', $html);
unset($item);
}

OR:

$html = preg_replace( '@<(script|iframe|style)[^>]*?>.*?</\\1>@si', '', $html );