zoukankan      html  css  js  c++  java
  • php strtok()函数用法,及使用时遇到的问题

    strtok()函数:用来将一段字符串分割为子字符串

    strtok(string $str, string $token)

    strtok( string $token) 

    //仅第一次调用$str,以后只使用$token,因为此函数会记住字符串,新字符串,只要在输入即可。。。

    //注意点:。。。。。。。。。。。。。。。

    //如果使用单引号包含带有转移字符的字符串,那么转义字符将失去意义。。

    
    //如果用单引号包含的话,那么是以\,n,t来分割字符串的
    
    //单引号:包含字符串,那么
    	就没有了意义,只是变成了字符
    //$str = 'This is	an example
    string';
    //得使用""才可以
    $str = 'This is	an example
    string';
    
    //$token = strtok($str, ' 
    	');
    //while ($token) {
    //    echo "word = $token <br />";
    //    $token = strtok(' 
    	');
    //}
    //输出
    /**
     * word = This
     * word = is
     * word = a
     * word = example
     * word = s
     * word = ri
     * word = g
     */
    
    //所以要注意
    
    //双引号包含
    //分割空格,
    ,	
    $token = strtok($str," 
    	");
    while ($token) {
        echo "word = $token <br />";
        $token = strtok(" 
    	");
    }
    //$string  =  "This is	an example
    string" ;
    ///* 使用制表符和换行符作为分界符 */
    //word = This 
    //word = is 
    //word = an 
    //word = example 
    //word = string
  • 相关阅读:
    SQL SERVER 2016研究三
    SQL SERVER 2016研究二
    SQL SERVER 2016研究一
    codeforce div2 426 D. The Bakery
    bzoj2190: [SDOI2008]仪仗队
    长路
    codechef AUG17 T5 Chef And Fibonacci Array
    codechef AUG17 T4 Palindromic Game
    codechef AUG17 T3 Greedy Candidates
    汕头市队赛 SRM10 dp只会看规律 && bzoj1766
  • 原文地址:https://www.cnblogs.com/tumio/p/4841157.html
Copyright © 2011-2022 走看看