Category Archives: Uncategorized

How to split a group of numbers to an array in PHP?

To split a number 187954 to an array as follows:

<?php
          $x=187954;
          $y=(string)$x;
          echo $y[0]."<br/>";  //1
          echo $y[1]."<br/>";  //8
          echo $y[2]."<br/>";  //7
          echo $y[3]."<br/>";  //9
          echo $y[4]."<br/>";  //5
          echo $y[5]."<br/>";  //4
?>

The Output will be as follows:

    1
    8
    7
    9
    5
    4

Advanced mail sending method in PHP

It’s as follows :

Page 1:config.php
class mymailer
    {
        function mysendmail($from,$to,$subject='sub',$body='msg',$content_type='text/html',$auth=true,$host=MAIL_HOST,$username=MAIL_USERNAME,$password=MAIL_PASSWORD)
        {
            require_once "Mail.php";   //you should install PEAR::Mail module in your server
            $headers = array ('From' => $from,
                'To' => $to,
                'Subject' => $subject,
                'Content-type'=>$content_type
            );
            $smtp = Mail::factory('smtp',
                array ('host' => $host,
                'auth' => $auth,
                'username' => $username,
                'password' => $password)
            );
            $mail = $smtp->send($to, $headers,$body);
            if (PEAR::isError($mail))
            {
                //return $mail->getMessage();
                return 'F';
            }
            else
            {
                return 'S';
            }
        }
    }

You can call this class as :

Page 2: mail_sending_page.php
require_once "config.php";
$from="frommail@company.com";
$to="tomail@example.com";
$subject="My Mail Subject";
$body="This is the body of this mail. Your content goes here.";
$mails=new mymailer;
$mails->mysendmail($from,$to,$subject,$body);

How to set a div fixed horizontally but not vertically?

To set the divs’ position horizontally fixed but not vertically, use the following code :

HTML

<div id="container">
    <div id="manu"></div>
</div>

CSS

<style type="text/css">
#container {
 position:relative;
    width:700px;
 height:1000px;
    top:50px;
    left:50px;
 background-color:yellow;

}

#manu{
    position:fixed;
    width:100px;
    height:100px;
    background-color:blue;
    margin-top:20px;
    margin-left:400px;
}
</style>

Jquery

<script type="text/javascript">
$(window).scroll(function(event) {
   $("#manu").css("margin-left", 400-$(document).scrollLeft());
});
</script>

To see demo please click the link below :

http://jsfiddle.net/kL33K/

How search a string in an array?

To search a content in an array in perl, we can use the following format,

my @a=('Hai','Leop','mac');
my @b = grep(/a/i, @a);
print join ",",@b;

The output will be as follows:

Hai,mac

How to get the size of a hash in Perl?

To get the hash in Perl ,

%hash=(
     a=>'Max',
     b=>'Rac',
     c=>'Neo'
);
print scalar keys(%hash);

The out put will be as follows:

3