第9章-字符串与正则表达式.pptx
文本预览下载声明
PHP与MySQL程序设计第9章 字符串和正则表达式目录字符串的定义字符串的输出正则表达式常用字符串函数正则表达式函数的替代函数小结字符串的定义双引号变量和转义序列都会得到解析。?php $sport = boxing; echo Jasons favorite sport is $sport.;?Jasons favorite sport is boxing.)字符串的定义转义序列?php $output = This is one line. \nAnd this is another line.; echo $output;?This is one line. And this is another line.)字符串的定义单引号变量和转义序列都不会得到解析。但是能够对单引号进行转义。?php print This string will $print exactly as it\s \n declared.;?This string will $print exactly as its \n declared.字符串的定义单引号但是,如果在字符串最后的存在一个反斜杠,那么此处的反斜杠必须转义。?php print This is another string.\\;?This is another string.\字符串的定义大括号 大括号可以用来对变量进行界定,表示大括号内部为变量。?php $capitals[ohio] = myOhio; echo The capital of Ohio is {$capitals[ohio]}.;?The capital of Ohio is myOhio.字符串的定义三个尖括号heredoc 为大量文本的输出和定义提供了便利。开始和结束的标识符必须相同,内容可以自定义?php $website = ; echo MYWORD 第十二届 法律文件。 $website;MYWORD;?结束标识符必须在一行开始处第十二届法律文件。 ;字符串的定义Nowdoc 操作类似于heredoc,但是不会解析界定在里面的内容。?php $website = ; echo MYWORD 第十二届 法律文件。 $website;MYWORD;?第十二届法律文件。 $website;目录字符串的定义字符串的输出正则表达式常用字符串函数正则表达式函数的替代函数小结字符串的输出print 向浏览器输出: int print(argument)?php print (“pI am a good student!/p”); $me = “good student”; print “I am a $me !”; print “I am a good student!”;?pI am a good student!/p字符串的输出echo 向浏览器输出:echo(string argument[,string argument,……])?php echo (“pI am a good student!/p”); $me = “good student”; echo “I am a $me !”,” and you?”,” OK”;?字符串的输出printf 格式化输出:integer printf(string format[,mixed args])?phpprintf(“Var inventory: %d bottles of tonic water.”,100);printf(“%d bottles of tonic water cost $%f”, 100,43.20);?字符串的输出printf 常用的类型指示符:类型描述类型描述%%返回一个百分号 %%f 浮点数(本地设置)%b二进制数%F浮点数(非本地设置)%cASCII 值对应的字符%g 较短的 %e 和 %f%d包含正负号的十进制数(负数、0、正数)%G较短的 %E 和 %f%e使用小写的科学计数法(例如 1.2e+2)%o八进制数%E使用大写的科学计数法(例如 1.2E+2)%s 字符串%u不包含正负号的十进制数(大于等于 0)%x十六进制数(小写字母)%X十六进制数(大写字母)字符串的输出sprintf 向变量格式化输出:string sprintf(string format[,mixed args])?php$cost = sprintf(“%d bottles of tonic water cost $%f”, 100,43.20);?目录字符串的定义字符串的输出正则表达式常用字符串函数正则表达式函数的替代函数小结正则表达式正则表达式的定义 正则表达式(regular expression)描述了一种字符串匹配的模式,可以用来检
显示全部