天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

PHP中的string類型使用說明

注意:php沒有對(duì)string的長(zhǎng)度做限制。唯一限制的就是php在計(jì)算機(jī)中的可用內(nèi)存(php.ini文件中的memory_limit變量的值)
限定字符串范圍的方法有4中:
1、單引號(hào);
2、雙引號(hào);
3、原型文檔語法;
4、nowdoc syntax(php5.3.0開始)

1、如果字符串使用單引號(hào)“‘”包裹,字符串中如果出現(xiàn)單引號(hào)“,”和反斜杠“/”符號(hào),需要進(jìn)行轉(zhuǎn)義。
復(fù)制代碼 代碼如下:
// Outputs: Arnold once said: "I'll be back"
echo 'Arnold once said: "I/'ll be back"';
// Outputs: You deleted C:/*.*?
echo 'You deleted C://*.*?';
// Outputs: You deleted C:/*.*?
echo 'You deleted C:/*.*?';

(有待驗(yàn)證 單引號(hào)包裹的字符串反斜杠是否需要轉(zhuǎn)義)

2、如果字符串被雙引號(hào)包裹 一下字符都會(huì)被轉(zhuǎn)義:
Escaped characters Sequence Meaning
/n linefeed (LF or 0x0A (10) in ASCII)
/r carriage return (CR or 0x0D (13) in ASCII)
/t horizontal tab (HT or 0x09 (9) in ASCII)
/v vertical tab (VT or 0x0B (11) in ASCII) (since php 5.2.5)
/f form 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

如果字符串 使用雙引號(hào)“"”或者原形文檔語法的形式包裹的話,在字符串中的變量會(huì)被解析。
1、簡(jiǎn)單語法:
因?yàn)榻馕銎鲿?huì)貪婪匹配$后面的字符,所以,為了不出什么以外,應(yīng)該使用"{"和"}"來表名變量的邊界。
復(fù)制代碼 代碼如下:
<?php
$beer = 'Heineken';
echo "$beer's taste is great"; // works; "'" is an invalid character for variable names
echo "He drank some $beers"; // won't work; 's' is a valid character for variable names but the variable is "$beer"
echo "He drank some ${beer}s"; // works
echo "He drank some {$beer}s"; // works
?>

同樣,數(shù)組的下標(biāo)和對(duì)象的屬性也會(huì)不解析。
復(fù)制代碼 代碼如下:
<?php
// These examples are specific to using arrays inside of strings.
// When outside of a string, always quote array string keys and do not use
// {braces}.
// Show all errors
error_reporting(E_ALL);
$fruits = array('strawberry' => 'red', 'banana' => 'yellow');
// Works, but note that this works differently outside a string
echo "A banana is $fruits[banana].";
// Works
echo "A banana is {$fruits['banana']}.";
// Works, but php looks for a constant named banana first, as described below.
echo "A banana is {$fruits[banana]}.";
// Won't work, use braces. This results in a parse error.
echo "A banana is $fruits['banana'].";
// Works
echo "A banana is " . $fruits['banana'] . ".";
// Works
echo "This square is $square->width meters broad.";
// Won't work. For a solution, see the complex syntax.
echo "This square is $square->width00 centimeters broad.";
?>

2、復(fù)合語法:
復(fù)制代碼 代碼如下:
<?php
// Show all errors
error_reporting(E_ALL);
$great = 'fantastic';
// Won't work, outputs: This is { fantastic}
echo "This is { $great}";
// Works, outputs: This is fantastic
echo "This is {$great}";
echo "This is ${great}";
// Works
echo "This square is {$square->width}00 centimeters broad.";
// Works
echo "This works: {$arr[4][3]}";
// This is wrong for the same reason as $foo[bar] is wrong outside a string.
// In other words, it will still work, but only because php first looks for a
// constant named foo; an error of level E_NOTICE (undefined constant) will be
// thrown.
echo "This is wrong: {$arr[foo][3]}";
// Works. When using multi-dimensional arrays, always use braces around arrays
// when inside of strings
echo "This works: {$arr['foo'][3]}";
// Works.
echo "This works: " . $arr['foo'][3];
echo "This works too: {$obj->values[3]->name}";
echo "This is the value of the var named $name: {${$name}}";
echo "This is the value of the var named by the return value of getName(): {${getName()}}";
echo "This is the value of the var named by the return value of /$object->getName(): {${$object->getName()}}";


訪問,修改字符串中的指定字符:
字符串可以使用"[]"和"{}"進(jìn)行訪問。(注意:php5.3.0以后不建議使用“{}”訪問)
注意:使用其他類型(非integer)類型訪問字符串指定的字符,都會(huì)返回NULL
警告:
Writing to an out of range offset pads the string with spaces. Non-integer types are converted to integer. Illegal offset type emits E_NOTICE. Negative offset emits E_NOTICE in write but reads empty string. Only the first character of an assigned string is used. Assigning empty string assigns NUL byte。

php技術(shù)PHP中的string類型使用說明,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 蜜柚视频在线观看全集免费观看 | 偷拍自怕亚洲在线第7页 | 国产亚洲欧美ai在线看片 | 午夜射精日本三级 | 国产99久久久国产精品成人 | 亚欧乱亚欧乱色视频 | 成人免费精品视频 | 草莓视频在线观看免费观看高清 | 亚洲国产精品无码中文字幕 | 亚洲最大日夜无码中文字幕 | 超碰 无码 中文字幕 | 极品少妇高潮啪啪AV无码吴梦梦 | 欧洲精品不卡1卡2卡三卡四卡 | 大咪咪dvd | 男人插曲女人身体视频 | 四虎精品久久久久影院 | 色婷婷五月综合久久中文字幕 | 抽插性奴中出乳精内射 | 忘忧草在线社区WWW日本直播 | 免费看国产曰批40分钟 | 熟女少妇内射日韩亚洲 | 超碰97人人做人人爱少妇 | 欧美亚洲天堂网 | 日本久久中文字幕 | 76人遣返航班上71人呈阳性 | 青青草原网址 | 国产午夜精品久久久久九九 | 国产免费网站看v片在线 | 国产精品一区二区三区四区五区 | 在线 | 果冻国产传媒61国产免费 | av av在线 | 国产欧美日韩精品a在线观看高清 | 女人会操出水图 | 精品免费视在线视频观看 | 日本无码免费久久久精品 | 精品国产免费观看久久久 | 伊人国产在线视频 | 免费可以看污动画软件 | 久久99re6热在线播放 | 男男gaygay拳头| 高h肉文np |