zoukankan      html  css  js  c++  java
  • PHP基础2

    1. sprintf  Replace the percent (%) sign by a variable passed as an argument:

    http://www.w3schools.com/php/func_string_sprintf.asp

    <?php
    $number = 9;
    $str = "Beijing";
    $txt = sprintf("There are %u million bicycles in %s.",$number,$str);
    echo $txt;
    ?>

     2. global variable

    using global variable inside function

    <?php
    function echo_ip(){
        global $user_ip;
        $string = "your ip addr is ".$user_ip;
        echo $string;
    }
    echo_ip();
    ?>

     3. print_r

    Prints human-readable information about a variable

    <?php
    $string = 'this is a example string';
    $string_word_count = str_word_count($string,1);
    print_r($string_word_count);
    ?>

     4. str_word_count

      second parameter

        0: the number of words

        1: put words in array,

        2. put words in array, key is the position of the words in the string

    <?php
    $string = 'this is a example string';
    $string_word_count = str_word_count($string,1);
    print_r($string_word_count);
    ?>

     the function ignore other character, to not ignore certain character

    <?php
    $string = 'this is a example string , $ &';
    $string_word_count = str_word_count($string,1,',&');
    print_r($string_word_count);
    ?>

     5. string concatenation

    dot

    <?php
    $string1 ='apple '.'banana';
    $string2 =' pig';
    echo $string1.$string2;
    ?>
  • 相关阅读:
    (转)SQL Server 2005两种安全验证模式
    C#练习题记录(交换两个数1)
    C# using 用法
    服务器的理解(菜鸟)
    zZ
    ZzZ
    [转]Arcgis制作泰森多边形具体步骤
    [转]免费网站推广
    [转]如何让Firefox优化得比Chrome更快
    [转]3天搞定网站重新被百度收录的方法
  • 原文地址:https://www.cnblogs.com/phoenix13suns/p/3604575.html
Copyright © 2011-2022 走看看