PHP ±äÁ¿¶¨ÒåºÍ±äÁ¿Ìæ»»µÄ·½·¨

5年以前  |  阅读数:1091 次  |  编程语言:PHP 

ÓÐÁ½ÖÖ½¨°Ñ±aÁ¿Ìae»»µ½×Öu´®ÖСª¡ª¼oµ¥µÄ½¨ºÍ¸´ÔӵĽ¨¡£
¼oµ¥µÄ
½¨ÊǰѱaÁ¿ÃuÅÔÚË«ÒýºÅ×Öu´®»oheredocÖУº
$who = ¡®Kilroy';
$where = ¡®here';
echo ¡°$who was $where¡±;
Kilroy was here
¸´ÔÓµÄ
½¨ÊÇ°ÑÒªÌae»»µÄ±aÁ¿ÓôoÀ¨ºÅÀ¨ÆðÀ´¡£ÕaÖÖ½¨¿ÉÒÔÓÃÓÚÏu³ýÆçÒa»oÌae»»Êý×e²eÕÒ¡£´oÀ¨ºÅµÄ¾­µa×÷ÓÃÊǰѱaÁ¿Ãu´ÓÖÜΧµÄÎı¾ÖÐÖ¸o³oÀ´£º
$n = 12;
echo ¡°You are the {$n}th person¡±;
You are the 12th person
Èç¹uûÓдoÀ¨ºÅµÄ»°£¬PHP¾Í»a³¢ÊÔ´oÓ¡³o±aÁ¿$nthµÄÖµ¡£
ºÍÒ»Ð(C)shell»¾³²»Í¬£¬ÔÚPHP×Öu´®ÖбaÁ¿²»»aÖظ´½aÎo£¬¶øÖ»´¦ÀiÔÚË«ÒýºÅ×Öu´®ÖеĽaÎo£¬È»ºo°ÑÆa½a¹u±»×÷Ϊ×Öu´®µÄÖµ£º
$bar = ¡®this is not printed';
$foo = ¡®$bar'; // µ¥ÒýºÅ
print(¡±$foo¡±); //Ë«ÒýºÅ
$bar
4.1.2 Óõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Öu´®
Single-Quoted Strings
Óõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Ö
u´®²¢²»Ìae»»±aÁ¿¡£ÒoΪ×Öu´®Ö±½ÓÁ¿ÊÇÓõ¥ÒýºÅÀ¨ÆðÀ´µÄ£¬ËuÒÔÔÚÏÂÃaeµÄ×Öu´®ÖбaÁ¿ÃuûÓб»½aÎo£º
$name = ¡®Fred';
$str = ¡®Hello, $name'; // single-quoted Óõ¥ÒýºÅÀ¨ÆðÀ´
echo $str;
Hello, $name
ÔÚÓõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Öu´®ÖÐΨһ¿ÉÓõÄתÒaÐoÁÐÊÇ \'£¨°Ñµ¥ÒýºÅÅÔÚÓõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Öu´®ÖУ(C)¡¢\\£¨°ÑÒ»¸o´Ð±¸ÜÅÔÚÓõ¥ÒýºÅÀ¨ÆðÀ´µÄ×Öu´®ÖУ(C)¡£ÈκÎÆaËuµÄ´Ð±¸ÜÖ»Äܱ»½aÊÍΪһ¸o´Ð±¸Ü£º
$name = ¡®Tim O\'Reilly'; //תÒaµÄµ¥ÒýºÅ
echo $name;
$path = ¡®C:\\WINDOWS'; //תÒaµÄ´Ð±¸Ü
echo $path;
$nope = ¡®\n'; // ²»ÊÇתÒaÐoÁÐ
echo $nope;
Tim O'Reilly
C:\WINDOWS
\n
4.1.3 ÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö
u´®
Double-Quoted Strings
ÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Öu´®½«»a½øÐбaÁ¿½aÎo²¢ÇÒÔÊÐiʹÓÃÐi¶aתÒaÐoÁС£±i4-1ÁгoÁËÔÚÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Öu´®ÖÐPHPÈϿɵÄתÒaÐoÁС£
±i4-1£ºÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Öu´®ÖеÄתÒaÐoÁÐ
תÒaÐoÁÐ ×Ö
uº¬Òa
\¡±
Ë«ÒýºÅ
\n
»»ÐÐ
\r
»Ø³µ
\t
ÖƱiu
\\
´Ð±¸Ü
\$
ÃÀÔªuºÅ
\{
×o´oÀ¨ºÅ
\}
ÓÒ´oÀ¨ºÅ
\[
×oÖÐÀ¨ºÅ
\]
ÓÒÖÐÀ¨ºÅ
\0 through \777
Óð˽øÖƱiʾµÄASCII×Ö
u
\x0 through \xFF
ÓÃÊ®Áu½øÖƱiʾµÄASCII×Öu
Èç¹uÔÚÓÃË«ÒýºÅÀ¨ÆðÀ´µÄ×Ö
u´®ÖТÏÖÒ»¸oδ֪µÄתÒaÐoÁУ¨ÀýÈ磬һ¸o´Ð±¸Üºo¸uÒ»¸o²»ÔÚ±i4-1ÖеÄ×Öu£(C)£¬¾ÍºoÂÔÕa¸oתÒaÐoÁУ¨Èç¹u¾¯¸ae¼¶ÉeÖÃΪE_NOTICE£¬¾Í»aΪÕaÑuµÄδ֪ÐoÁвuÉuÒ»¸o¾¯¸ae£(C)£º
$str = ¡°What is \c this?¡±; // δ֪µÄתÒaÐoÁÐ
echo $str ;
What is \c this?
4.1.4 ×Ö
u´®¶¨½ç
Here Documents heredoc
ʹÓÃheredoc¿ÉÒÔ¼oµ¥µØ°Ñ¶aÐÐ×Öu´®ÅÔÚ³ÌÐoÖУ¬ÈçÏÂËuʾ£º
$clerihew = <<< End_Of_Quote
Sir Humphrey Davy
Abominated gravy.
He lived in the odium
Of having discovered sodium.
End_Of_Quote;
echo $clerihew;
Sir Humphrey Davy
Abominated gravy.
He lived in the odium
Of having discovered sodium.
<<<uºÅ£¨ÎÒÃÇÏ°¹ß³ÆΪ×Öu´®¶¨½çu¨D¨DÒeÕß×¢£(C)¸aeËßPHP½aÎoÆ÷ÄaÕýÔÚÊeдһ¸oheredoc¡£ÔÚ<<<uºÅºÍ±eʶu£¨±¾ÀýÖм´ End_Of_Quote£(C)Ö®¼a±ØÐeÓÐÒ»¸o¿Õ¸ñ£¬ÕaÑu³ÌÐo²Å¿ÉÒÔ±ae±ð±eʶu¡£´ÓÏÂÒ»ÐпªÊ¼¾ÍÊDZ»ÒýÓõÄÎı¾£¬Ö±µ½ËuÓoµ½½oÓɱeʶu×e³ÉµÄÒ»ÐÐΪֹ¡£
Äa¿ÉÒÔ°Ñ
ÖºÅÅÔÚÖÕÖ¹±eʶuµÄºoÃaeÀ´½aÊøÓi¾a£¬ÕýÈçÇ°ÃaeµÄ´uÂeËuʾ¡£Èç¹uÄaÔÚÒ»¸o¸u¸´Ôӵıi´iʽÖÐʹÓÃheredoc£¬ÄaÐeÒª½«±i´iʽÖÐÐÀ´Ð´£º
printf(<<< Template
%s is %d years old.
Template
, ¡°Fred¡±, 35);
ÔÚheredocÖеĵ¥ÒýºÅºÍË«ÒýºÅ±»Ìø¹ý£¨µ±×÷Ò»°aµÄ
uºÅ£(C)£º
$dialogue = <<< No_More
¡°It's not going to happen!¡± she fumed.
He raised an eyebrow. ¡°Want to bet?¡±
No_More;
echo $dialogue;
¡°It's not going to happen!¡± she fumed.
He raised an eyebrow. ¡°Want to bet?¡±
ÔÚheredocÖеĿհ×uÒ²±»±£Áo£º
$ws = <<< Enough
boo
hoo
Enough;
// $ws = ¡± boo\n hoo\n¡±;
ÒoΪÔÚ½aβÖÕÖ¹
uÇ°µÄ»»ÐÐu½«±»ÒƳý£¬ËuÒÔÏÂÃaeÕaÁ½¸o¸³ÖµÊÇÏaͬµÄ£º
$s = ¡®Foo';
// same as ºÍÏÂÃaeµÄÏaͬ
$s = <<< End_of_pointless_heredoc
Foo
End_of_pointless_heredoc;
Èç¹uÏeÓÃÒ»¸o»»ÐÐ
uÀ´½aÊøheredocÒýÓõÄ×Ö*u´®£¬ÔoÐeÒª×Ô¼º¶iÍa¼ÓÈe£º
$s = <<< End
Foo

End;
//×¢ÒaFooºoÃae¸uÒ»¸o¿ÕÐУ¬²»¿Éɾ³ý

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
文件下载
贪吃蛇
双位运算符
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
发送邮件
年的日历图
提取后缀名
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例