zoukankan      html  css  js  c++  java
  • 字符串的定义和处理(续)

    额。。。这几天晚上都有事所以都没怎么学习,真是罪过啊,罪过。。

    这个是接着上一篇的结尾处的内容继续的:

    对url处理
         parse_str(string str):将字符串解析到变量中,例如
                   parse_str("a=2&b=4&c=5");
                   echo $a."-----";
                   echo $b;
                   输出结果为:2-----4
     
         parse_str(string str,array arr):将解析到的字符串存储到arr数组中,例如
                   parse_str("a=2&b=3&c=4",$arr);
                   print_r($arr);
              
         parse_url(string $url[, int $component = -1 ]): 对url字符串进行解析,并将结果返回数组中 php上的解释:http://www.php.net/manual/zh/function.parse-url.php
              参数:
                   url:要解析的 URL。无效字符将使用 _ 来替换。
                   component:指定 PHP_URL_SCHEME、 PHP_URL_HOST、 PHP_URL_PORT、 PHP_URL_USER、 PHP_URL_PASS、 PHP_URL_PATH、 PHP_URL_QUERY 或 PHP_URL_FRAGMENT 的其中一个来获取 URL 中指定的部分的 string。 (除了指定为 PHP_URL_PORT 后,将返回一个 integer 的值)。
              
                   $parseURL = parse_url("http://www.baidu.com?a=23&b=2");
                   print_r($parseURL);
                   输出结果 :Array ( [scheme] => http [host] => www.baidu.com [query] => a=23&b=2 )
                   一般情况下,用的最多的应该是[query]这个了
     
                   还会有一些其他的参数。如下:
          • scheme - 如 http
          • host
          • port
          • user
          • pass
          • path
          • query - 在问号 ? 之后
          • fragment - 在散列符号 # 之后
                 如果指定了 component 参数, parse_url() 返回一个 string (或在指定为 PHP_URL_PORT 时返回一个 integer)而不是array。如果 URL 中指定的组成部分不存在,将会返回 NULL  
                       
              又一个例子:
             
    <?php
    $url 'http://username:password@hostname/path?arg=value#anchor';
    print_r(parse_url($url));
    echo 
    parse_url($urlPHP_URL_PATH);
    ?>

    以上例程会输出:

    Array
    (
        [scheme] => http
        [host] => hostname
        [user] => username
        [pass] => password
        [path] => /path
        [query] => arg=value
        [fragment] => anchor
    )
    /path
    
         
         url编码处理函数:
         rawurlencode(string $str);按照RFC编码规则进行编码,将空格编码成%20
         rawurldecode(string $str):对已经编码的url进行解码
         urlencode():对url进行编码,将空格编码成+
         urldecode():对url进行解码
     
         构造查询字符串等:
         http_build_query(); http://cn2.php.net/manual/zh/function.http-build-query.php 生成 URL-encode 之后的请求字符串,例子:
              
    <?php
    $data 
    = array('foo'=>'bar',
                  
    'baz'=>'boom',
                  
    'cow'=>'milk',
                  
    'php'=>'hypertext processor');

    echo 
    http_build_query($data) . " ";
    echo 
    http_build_query($data'''&amp;');

    ?>

    以上例程会输出:

    foo=bar&baz=boom&cow=milk&php=hypertext+processor
    foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor
    
     
    对url处理
         parse_str(string str):将字符串解析到变量中,例如
                   parse_str("a=2&b=4&c=5");
                   echo $a."-----";
                   echo $b;
                   输出结果为:2-----4
     
         parse_str(string str,array arr):将解析到的字符串存储到arr数组中,例如
                   parse_str("a=2&b=3&c=4",$arr);
                   print_r($arr);
              
         parse_url(string $url[, int $component = -1 ]): 对url字符串进行解析,并将结果返回数组中 php上的解释:http://www.php.net/manual/zh/function.parse-url.php
              参数:
                   url:要解析的 URL。无效字符将使用 _ 来替换。
                   component:指定 PHP_URL_SCHEME、 PHP_URL_HOST、 PHP_URL_PORT、 PHP_URL_USER、 PHP_URL_PASS、 PHP_URL_PATH、 PHP_URL_QUERY 或 PHP_URL_FRAGMENT 的其中一个来获取 URL 中指定的部分的 string。 (除了指定为 PHP_URL_PORT 后,将返回一个 integer 的值)。
              
                   $parseURL = parse_url("http://www.baidu.com?a=23&b=2");
                   print_r($parseURL);
                   输出结果 :Array ( [scheme] => http [host] => www.baidu.com [query] => a=23&b=2 )
                   一般情况下,用的最多的应该是[query]这个了
     
                   还会有一些其他的参数。如下:
          • scheme - 如 http
          • host
          • port
          • user
          • pass
          • path
          • query - 在问号 ? 之后
          • fragment - 在散列符号 # 之后
                 如果指定了 component 参数, parse_url() 返回一个 string (或在指定为 PHP_URL_PORT 时返回一个 integer)而不是array。如果 URL 中指定的组成部分不存在,将会返回 NULL  
                       
              又一个例子:
             
    <?php
    $url 'http://username:password@hostname/path?arg=value#anchor';
    print_r(parse_url($url));
    echo 
    parse_url($urlPHP_URL_PATH);
    ?>

    以上例程会输出:

    Array
    (
        [scheme] => http
        [host] => hostname
        [user] => username
        [pass] => password
        [path] => /path
        [query] => arg=value
        [fragment] => anchor
    )
    /path
    
         
         url编码处理函数:
         rawurlencode(string $str);按照RFC编码规则进行编码,将空格编码成%20
         rawurldecode(string $str):对已经编码的url进行解码
         urlencode():对url进行编码,将空格编码成+
         urldecode():对url进行解码
     
         构造查询字符串等:
         http_build_query(); http://cn2.php.net/manual/zh/function.http-build-query.php 生成 URL-encode 之后的请求字符串,例子:
              
    <?php
    $data 
    = array('foo'=>'bar',
                  
    'baz'=>'boom',
                  
    'cow'=>'milk',
                  
    'php'=>'hypertext processor');

    echo 
    http_build_query($data) . " ";
    echo 
    http_build_query($data'''&amp;');

    ?>

    以上例程会输出:

    foo=bar&baz=boom&cow=milk&php=hypertext+processor
    foo=bar&amp;baz=boom&amp;cow=milk&amp;php=hypertext+processor
    
     
  • 相关阅读:
    清除Jpanel组件并重绘
    idea配置ssm框架
    java异常机制
    JavaSwing关于GridBagLayout(网格袋布局)的使用
    (趣味哈哈镜)JMF中摄像头相关的问题
    三大WEB服务器(apache lighttpd nginx) 对比分析
    在前台接收jsonp数据(练习)
    cookie存数组的方法
    接口验证每个ip每小时只能访问2次(自己实验:有待改进)
    DOM操作xml数据
  • 原文地址:https://www.cnblogs.com/xyhy/p/3813184.html
Copyright © 2011-2022 走看看