Redirect through .htaccess file

Here’ s the logic to redirect particular page through .htaccess file.

RewriteCond %{HTTP_HOST} ^avidindiainc.com [NC]
RewriteRule ^(.*)$ http://www.avidindiainc.com/$1 [L,R=301]

as given above,
here avidindiainc.com is the url of the site you want to redirect. here if the url typed in the address bar is http://avidindiainc.com, it will redirect to http://www.avidindiainc.com.

the above given logic will work for apache webserver only as .htaccess file is supported by apache webserver and not IIS webserver. In case you have an IIS webserver here’s something you can do.

But this logic has to be written in php file. The logic follows as below:

<?php

if($_SERVER[‘SERVER_SOFTWARE’]==’Microsoft-IIS/6.0′){
if($_SERVER[‘HTTP_HOST’]!=’www.theartel.com’){
header( “HTTP/1.1 301 Moved Permanently” );
if($_SERVER[‘argv’])
header( “Location: http://www.&#8221;.$_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’].’?’.@implode(‘&’,$_SERVER[‘argv’]));
else
header( “Location: http://www.&#8221;.$_SERVER[‘HTTP_HOST’].$_SERVER[‘PHP_SELF’]);
}
}


?>

thanks,

Sachin

Remove blank spaces and new lines from string

you can use the preg_replace function to compress a given string and remove spaces and blank lines from the string.

The use of the function is as given below:

preg_replace(“/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/”, “\n”, $string);

where “$string” is the string you want to remove the spaces and blank lines from.

if in case the above code doesn’t work properly you can use the below given user-defined function :

The Function:

function my_preg_rep($content_area){
$content_area=preg_replace(“/[\r\n]*/”, “”, $content_area);
$content_area=preg_replace(“/[\r\n]+/”, “”, $content_area);
return $content_area;
}

Code :

echo my_preg_rep(addslashes($content_area));

thanks,

Sachin (samsami2um@gmail.com)

Automatic destructor in PHP4

<?php
class demoClass{

function demoClass(){
//destructor
register_shutdown_function(array(&$this, ‘__destruct’));

//constructor
$argcv = func_get_args();
call_user_func_array(array(&$this, ‘__construct’), $argcv);
}

function __construct(){
//your code for constructor goes here
}

function __destruct(){
//your code for destructor goes here
}

}

//Hope this method help you out with your problems.

//Hope this helps you,

//Sachin (samsami2u@gmail.com)
?>