您的位置:首页 > 编程语言 > PHP开发

php手册 笔记 类型 -- 字符串类型

2011-01-26 21:36 399 查看
1. 除了//,/'之外,其他的都按原来的显示

 

2. 

/nlinefeed (LF or 0x0A (10) in ASCII)
/rcarriage return (CR or 0x0D (13) in ASCII)
/thorizontal tab (HT or 0x09 (9) in ASCII)
/vvertical tab (VT or 0x0B (11) in ASCII) (since PHP 5.2.5)
/fform feed (FF or 0x0C (12) in ASCII) (since PHP 5.2.5)
//backslash
/$dollar sign
/"double-quote
/[0-7]{1,3}the sequence of characters matching the regular expression is a character in octal notation
/x[0-9A-Fa-f]{1,2}the sequence of characters matching the regular expression is a character in hexadecimal notation

 

 

 

 

3.  php4之后可以使用这个东西heredoc。<<<mystring,然后新行,结束必须在第一列,而且除了;之外,不能有其他的符号,包括空格,或者缩进等(反正不能有任何东西了),在结束标志之后也需要一个新行,这个东西不能在类的属性里直接赋值

 

4. <<<5.3版本之后,可以使用在静态变量里,也可使用在类的属性和类的常量里面;标识符也可以用双引号引起来

<?php
echo <<<"FOOBAR"
Hello World!
FOOBAR;
?>

 

5. nowdoc,跟heredoc一样,只是nowdoc用单引号,不解析,可以使用在任何的变量赋值,包括类;这个是php5.3增加的

$str = <<<'EOD'
Example of string
spanning multiple lines
using nowdoc syntax.
EOD;

 

6. {$var},$要紧跟着{,如果有空格就不行。

echo "This works: {$arr['key']}";只有使用{}才能使用数组的key。

---------------------------------------------

class foo {
    var $bar = 'I am bar.';
}

$foo = new foo();
$bar = 'bar';
$baz = array('foo', 'bar', 'baz'
4000
, 'quux');
echo "{$foo->$bar}/n";//注意这里的$bar
echo "{$foo->$baz[1]}/n";

-----------------------------------------------------------

 

7. $str{42},$str[1]

 

8. $str{},超出范围,或者非数字类型(负数)的处理

 

9. echo "foo {Test::ONE} bar";类的静态静态属性和常量,不显示;好像一定是需要$;在php5之后,可以把函数赋给变量,然后里面调用。如:

 function x(){}

$x='x';

"{$x()}"

 

10. 注意 > , < 的功能,能比较日期?文档里面没有

$a = '2007-11-05 15:17:49';
$b = '2007-11-05 15:17:48';

$bool = $a > $b;

var_dump($bool); //bool(true)


 

11. 大括号总是现执行,并且返回值作为变量

${date("M")} = "Worked";

echo ${date("M")};


 

12. echo hello.world._6789;将会解析成字符串?

 

13. <?php $binary = b'This is a binary string'; ?>定义一个binary类型的字符串

 

14. <?php

$str = '';
$str[0] = 'a';

echo $str."/n"; // => Array


空字符串

 

15. ``反引号在heredoc里面不起作用

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息