PHP String (iii)

Source: Internet
Author: User

  
 
  1. $f=(string)1050089;
  2. for($i=0;$i<strlen($f);$i++){
  3. //echo $f{$i}.‘<br>‘; //把102输出把数字转换成字符串输出
  4. //echo substr($f, $i,1).‘<br>‘;//把102输出把数字转换成字符串输出
Statistics Total Traffic
  
 
  1. $f=(string)1050089;
  2. $info="共";
  3. for($i=0;$i<strlen($f);$i++){
  4. $s=substr($f, $i,1);
  5. $info.=";
  6. }
  7. echo $info. ‘人访问‘;

Regular expressions
Regular expression substitution
  
 
    1. $p="/a+/"; //+表示一个以上 .表示任意字符 *0个或者多个字符
    2. $str ="java aap mysql";
    3. echo preg_replace($p, ‘*‘, $str);
Regular expression Verification phone number
 
   
  
  1. $telp="/^1[3,5,,8][0-9]{9}$/";
  2. $aa="1871799698";
  3. echo preg_match($telp, $aa);
The regular expression must be 126 mailboxes,
 
   
  
  1. $mailp = "/^[a-z]{1}[a-z_0-9]{3,6}@126\.com$/"
  2. $ EM = "[email protected]"
  3. ( $mailp $em );
The regular expression Preg_match found returned 1 did not find return 0, Preg_match_all found the number of returns, did not find return 0
  
 
  1. $ps="/\d/";
  2. $s="he54 p12 ja544";
  3. echo preg_match($ps, $s);//1
  4. echo preg_match_all($ps, $s);//7
  
 
  1. $ps="/\d/";
  2. $s="he54 p12 ja544";
  3. echo preg_match_all($ps, $s,$a);
  4. echo ‘<pre>‘;
  5. print_r($a);//打印处找到的数组
Regular expression judgment
  
 
  1. $p="/^\w{6,8}$/";//\w表示0-9 _a-z
  2. $s="111111111";
  3. if(preg_match($p,$s)){
  4. echo ‘账号合理‘;
  5. }else{
  6. echo ‘账号非法‘;
  7. }
PHP build file Add content Close function
 
   
  
  1. $f=fopen("f:/a.txt","a");//a为追加没有就会自动建立
  2. fwrite($f,‘12‘);//12为填写的内容,执行一次就填入一次
  3. //fclose($f);
\ r \ n line break 8 means append, refresh once display once
 
   
  
  1. file_put_contents(‘ab.txt‘, "asdf\r\n",8);//写入数据
 
   
  
  1. file_get_contents(‘a.txt‘); //读取数据
 
   
  
  1. file_exists()//判断文件是否存在



echo count (file (_file_)); Statistics on the number of money bar information
echo is_dir (' F:/mysql '); Find if there is a f:/mysql if present returns 1 does not exist return 0;




From for notes (Wiz)

PHP String (iii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.