PHP Persian Requirements Digest

Converting English Number to Farsi:

function eng_num2farsi($string){
        $string = str_replace('0','۰',$string);
        $string = str_replace('1','۱',$string);
        $string = str_replace('2','۲',$string);
        $string = str_replace('3','۳',$string);
        $string = str_replace('4','۴',$string);
        $string = str_replace('5','۵',$string);
        $string = str_replace('6','۶',$string);
        $string = str_replace('7','۷',$string);
        $string = str_replace('8','۸',$string);
        $string = str_replace('9','۹',$string);
        return $string;
}

Converting Farsi Number to English:

function farsi_num2eng($string){
        $string = str_replace('۰','0',$string);
        $string = str_replace('۱','1',$string);
        $string = str_replace('۲','2',$string);
        $string = str_replace('۳','3',$string);
        $string = str_replace('۴','4',$string);
        $string = str_replace('۵','5',$string);
        $string = str_replace('۶','6',$string);
        $string = str_replace('۷','7',$string);
        $string = str_replace('۸','8',$string);
        $string = str_replace('۹','9',$string);
        return $string;
}  


Mysql Get Query Digest

require(constant("sec_inc").'/config.php');
$link=mysql_connect($host,$user,$pass);
mysql_select_db($dbname);

Fetch:

$query = "select * from table_name  where field='".$var."'";//Don't forget escaping...
mysql_query("SET NAMES 'utf8'", $link);
$result=mysql_query($query);
while($row=mysql_fetch_assoc($result))
{

         //Bla Bla Bla

}

 

Count:

$query = "select count(*) from table_name  where field='".$var."'";//Don't forget escaping...
$row=mysql_fetch_row($result);
$count = $row[0];

 

PHPMailer Digest

PHPMailer is a PHP class for PHP that provides a package of functions to send email. The two primary features are sending HTML Email and e-mails with attachments. PHPMailer supports nearly all possiblities to send email: mail(), Sendmail, qmail & direct to SMTP server. You can use any feature of SMTP-based e-mail, multiple recepients via to, CC, BCC, etc. In short: PHPMailer is an efficient way to send e-mail within PHP.

Download Link: http://phpmailer.worxware.com/

============

<?php
require("class.phpmailer.php");

$mail = new PHPMailer();
$mail->IsMail();
$mail->From = "info@from.net";
$mail->FromName = "sender name";
$mail->AddAddress("receiver email");
$mail->AddReplyTo("info@from.net","sender name");
$mail->IsHTML(true);
$mail->CharSet="utf-8";
           $mail->Subject ="Subject"
           $mail->Body = "<p>Hello!</p>";
           if(!$mail->Send()) {
               echo 'Message was not sent.';
               echo 'Mailer error: ' . $mail->ErrorInfo;
           } else {
               echo 'Message has been sent.';
           }
?>

Continue reading “PHPMailer Digest”

PHP Validation Digest

Email:

function is_valid_email($email) {
       $result = TRUE;
       if(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $email)) {
           $result = FALSE;
       }
       return $result;
   }
Moblie:
function is_valid_mobile($mobile) {
    $result = TRUE;
    if(preg_match("/[^0-9]/", $mobile))
    {
        $result = FALSE;
    }
    elseif(strlen($mobile)!=11)
    {
        $result = FALSE;
    }
    elseif(substr($mobile,0,2)!="09")
    {
        $result = FALSE;
    }

    return $result;
}