·ÖÏí10¶ÎPHP³£ÓôúÂë

5年以前  |  阅读数:475 次  |  编程语言:PHP 

±¾ÎÄ»a¼¯PHP¿ª*¢Öо­³£Óõ½µÄÊ®¶Î´uÂe£¬°uÀ¨Email¡¢64λ±aÂeºÍ½aÂe¡¢½aѹËo¡¢64λ±aÂe¡¢½aÎoJSONµÈ£¬Ï£Íu¶ÔÄuÓÐËu°iÖu¡£

*1¡¢Ê¹ÓÃPHP Mailº¯Êý¢ËÍEmail**


    $to = "viralpatel.net@gmail.com"; 
    $subject = "VIRALPATEL.net"; 
    $body = "Body of your message here you can use HTML too. e.g. (C)‚br(C)ƒ (C)‚b(C)ƒ Bold (C)‚/b(C)ƒ"; 
    $headers = "From: Peter\r\n"; 
    $headers .= "Reply-To: info@yoursite.com\r\n"; 
    $headers .= "Return-Path: info@yoursite.com\r\n"; 
    $headers .= "X-Mailer: PHP5\n"; 
    $headers .= 'MIME-Version: 1.0' . "\n"; 
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
    mail($to,$subject,$body,$headers); 
    ?(C)ƒ

2¡¢PHPÖеÄ64λ±aÂeºÍ½aÂe


    function base64url_encode($plainText) {
    $base64 = base64_encode($plainText);
    $base64url = strtr($base64, '+/=', '-_,');
    return $base64url;
    }
    function base64url_decode($plainText) {
    $base64url = strtr($plainText, '-_,', '+/=');
    $base64 = base64_decode($base64url);
    return $base64;
    } 

**3¡¢»ñÈ¡Ô¶³ÌIPµØÖ***


    function getRealIPAddr()
    {
    if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
    {
    $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
    {
    $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
    $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
    }

4¡¢ ÈÕÆÚ¸ñʽ»¯


    function checkDateFormat($date)
    {
    //match the format of the date
    if (preg_match ("/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/", $date, $parts))
    {
    //check weather the date is valid of not
    if(checkdate($parts[2],$parts[3],$parts[1]))
    return true;
    else
    return false;
    }
    else
    return false;
    }

5¡¢ÑeÖ¤Email


    $email = $_POST['email'];
    if(preg_match("~([a-zA-Z0-9!#$%&'*+-/=?^_`{|}~])@([a-zA-Z0-9-]).
       ([a-zA-Z0-9]{2,4})~",$email)) {
    echo 'This is a valid email.';
    } else{
    echo 'This is an invalid email.';
    }

6¡¢ÔÚPHPÖÐÇaËɽaÎoXML


    //this is a sample xml string
    $xml_string="(C)‚?xml version='1.0'?(C)ƒ
    (C)‚moleculedb(C)ƒ
     (C)‚molecule name='Benzine'(C)ƒ
     (C)‚symbol(C)ƒben(C)‚/symbol(C)ƒ
     (C)‚code(C)ƒA(C)‚/code(C)ƒ
     (C)‚/molecule(C)ƒ
     (C)‚molecule name='Water'(C)ƒ
     (C)‚symbol(C)ƒh2o(C)‚/symbol(C)ƒ
     (C)‚code(C)ƒK(C)‚/code(C)ƒ
     (C)‚/molecule(C)ƒ
    (C)‚/moleculedb(C)ƒ";
    //load the xml string using simplexml function
    $xml = simplexml_load_string($xml_string);
    //loop through the each node of molecule
    foreach ($xml-(C)ƒmolecule as $record)
    {
     //attribute are accessted by
     echo $record['name'], ' ';
     //node are accessted by -(C)ƒ operator
     echo $record-(C)ƒsymbol, ' ';
     echo $record-(C)ƒcode, '(C)‚br /(C)ƒ';
    }

7¡¢Êý¾Ý¿aÁ¬½Ó


    (C)‚?php
    if(basename(__FILE__) == basename($_SERVER['PHP_SELF'])) send_404();
    $dbHost = "localhost"; //Location Of Database usually its localhost
    $dbUser = "xxxx"; //Database User Name
    $dbPass = "xxxx"; //Database Password
    $dbDatabase = "xxxx"; //Database Name
    $db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or 
       die ("Error connecting to database.");
    mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database.");
    # This function will send an imitation 404 page if the user
    # types in this files filename into the address bar.
    # only files connecting with in the same directory as this
    # file will be able to use it as well.
    function send_404()
    {
     header('HTTP/1.x 404 Not Found');
     print '(C)‚!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"(C)ƒ'."n".
     '(C)‚html(C)ƒ(C)‚head(C)ƒ'."n".
     '(C)‚title(C)ƒ404 Not Found(C)‚/title(C)ƒ'."n".
     '(C)‚/head(C)ƒ(C)‚body(C)ƒ'."n".
     '(C)‚h1(C)ƒNot Found(C)‚/h1(C)ƒ'."n".
     '(C)‚p(C)ƒThe requested URL '.
     str_replace(strstr($_SERVER['REQUEST_URI'], '?'), '', $_SERVER['REQUEST_URI']).
     ' was not found on this server.(C)‚/p(C)ƒ'."n".
     '(C)‚/body(C)ƒ(C)‚/html(C)ƒ'."n";
     exit;
    }
    # In any file you want to connect to the database,
    # and in this case we will name this file db.php
    # just add this line of php code (without the pound sign):
    # include"db.php";
    ?(C)ƒ

8¡¢´´½¨ºÍ½aÎoJSONÊý¾Ý


    $json_data = array ('id'=(C)ƒ1,'name'=(C)ƒ"rolf",'country'=(C)ƒ'russia',
    "office"=(C)ƒarray("google","oracle"));
    echo json_encode($json_data);

9¡¢´¦ÀiMySQLʱ¼a´Á


    $query = "select UNIX_TIMESTAMP(date_field) as mydate 
     from mytable where 1=1";
    $records = mysql_query($query) or die(mysql_error());
    while($row = mysql_fetch_array($records))
    {
    echo $row;
    }

10¡¢½aѹËoZipÎļþ


    (C)‚?php
     function unzip($location,$newLocation){
     if(exec("unzip $location",$arr)){
     mkdir($newLocation);
     for($i = 1;$i(C)‚ count($arr);$i++){
     $file = trim(preg_replace("~inflating: ~","",$arr[$i]));
     copy($location.'/'.$file,$newLocation.'/'.$file);
     unlink($location.'/'.$file);
     }
     return TRUE;
     }else{
     return FALSE;
     }
     }
    ?(C)ƒ
    //Use the code as following:
    (C)‚?php
    include 'functions.php';
    if(unzip('zipedfiles/test.zip','unziped/myNewZip'))
     echo 'Success!';
    else
     echo 'Error';
    ?(C)ƒ

PHP³£Óù¦ÄÜÈçÏÂ

*1.PHP×Öu´®**

×Öu´®ÉuÃ÷ ±aÁ¿=''»oÕß""£¨Ò»°aÇe¿o»aʹÓõ¥ÒýºÅ£¬ÒoΪдÆðÀ´»a±È½Ï½±a£(C)

$str = 'Hello PHP';
echo $str;

strpos ¼ÆËa×ÖuÔÚ×Öu´®ÖеÄλÖ㨴Ó0¿ªÊ¼£(C)

$str = 'Hello PHP';
echo strpos($str,'o'); //¼ÆËa×ÖuÔÚ×Öu´®ÖеÄλÖÃ
echo '
';
echo strpos($str,'PH');

*substr ½ØÈ¡×Öu´® **


    $str = 'Hello PHP';
    //½ØÈ¡×Ö*u´®
    $str1 = substr($str,2,3); //´Ó2λÖÿªÊ¼½ØÈ¡£¬½ØÈ¡³¤¶ÈΪ3µÄ×Ö*u´®
    echo $str1;

²»´«Èe³¤¶È²ÎÊýµÄ»°£¬»a´ÓÖ¸¶¨Î»ÖÃÒ»Ö±½ØÈ¡µ½×Ö*u´®µÄÄ(C)β

str_split Ö¸i×Öu´® ¹Ì¶¨³¤¶ÈµÄ*Ö¸i£¨Ä¬Èϳ¤¶ÈΪ1£(C)


    $str = 'Hello PHP';
    //*Ö¸i×Ö*u´®
    $result = str_split($str); //½«½a¹u±£´aeµ½Ò»¸oÊý×eÖÐ
    print_r($result); //ʹÓÃprint_rÊaÈeÒ»¸oÊý×e
    echo '<br/>';
    $result1 = str_split($str,2);
    print_r($result1);

explode(Ö¸i×Öu,´ýÖ¸iµÄ×Öu´®) °´ÕÕ¿Õ¸ñ½øÐÐ*Ö¸i


    $str = 'Hello PHP Java C# C++';
    $result = explode(' ',$str);
    print_r($result);

*×Öu´®µÄÁ¬½Ó**


    $str = 'Hello PHP Java C# C++';
    //×Ö*u´®µÄÁ¬½Ó
    $num = 100;
    $str1 = $str.'<br/>Objective-C '.$num;
    echo $str1;
    echo '<br/>';
    $str2 = "$str<br/>Objective-C $num"; //ÁiÒ»Öмo±aµÄд*¨
    echo $str2;
 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例