<?php if(preg_match('/(?i)msie [1-8]/',$_SERVER['HTTP_USER_AGENT']))
{
// if IE<=8
include ( TEMPLATEPATH . '/noie.php' );
exit;
}
else
{
// if IE>8
} ?>
Category Archives: PHP
Function to remove HTML form text
function html2text($html)
{
$tags = array (
0 => ‘~<h[123][^>]+>~si’,
1 => ‘~<h[456][^>]+>~si’,
2 => ‘~<table[^>]+>~si’,
3 => ‘~<tr[^>]+>~si’,
4 => ‘~<li[^>]+>~si’,
5 => ‘~<br[^>]+>~si’,
6 => ‘~<p[^>]+>~si’,
7 => ‘~<div[^>]+>~si’,
);
$html = preg_replace($tags,”\n”,$html);
$html = preg_replace(‘~</t(d|h)>\s*<t(d|h)[^>]+>~si’,’ – ‘,$html);
$html = preg_replace(‘~<[^>]+>~s’,”,$html);
// reducing spaces
$html = preg_replace(‘~ +~s’,’ ‘,$html);
$html = preg_replace(‘~^\s+~m’,”,$html);
$html = preg_replace(‘~\s+$~m’,”,$html);
// reducing newlines
$html = preg_replace(‘~\n+~s’,”\n”,$html);
return $html;
}
echo html2text($html);
PHP Browser Detecting
<?php
if(strpos($_SERVER[‘HTTP_USER_AGENT’], ‘MSIE’) !== FALSE)
echo ‘Internet explorer’;
elseif(strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Firefox’) !== FALSE)
echo ‘Mozilla Firefox’;
elseif(strpos($_SERVER[‘HTTP_USER_AGENT’], ‘Chrome’) !== FALSE)
echo ‘Google Chrome’;
else
echo ‘Something else’;
?>
Dispaly Current page URL
<?php
function curPageURL() {
$pageURL = ‘http’;
if ($_SERVER[“HTTPS”] == “on”) {$pageURL .= “s”;}
$pageURL .= “://”;
if ($_SERVER[“SERVER_PORT”] != “80”) {
$pageURL .= $_SERVER[“SERVER_NAME”].”:”.$_SERVER[“SERVER_PORT”].$_SERVER[“REQUEST_URI”];
} else {
$pageURL .= $_SERVER[“SERVER_NAME”].$_SERVER[“REQUEST_URI”];
}
return $pageURL;
}
?>
<?php echo curPageURL();
$myurl = curPageURL(); ?>