<?php // 1.单引号定义字符串 // 2.双引号定义字符串 // 3.定界符定义字符串 // 1.单引号定义字符串 // echo 'this is 'my' mother'; echo 'this is \'my\' mother <br>'; // 单引号不能解析转义符\n 换行 \t 缩进 echo 'this \n is a simple \t string<br>'; $username = 'admin'; echo '欢迎您,$username<br>'; echo '<hr>'; // 双引号如此强大为何还要用单引号? 越健全封装就越复杂 // 双引号定义字符串 // 双引号能解析转义符\n 换行 \t 缩进 echo "this \n is a simple \t string<br>"; $Omega ='苏米'; $Alpha = '沈晗'; echo "喜欢$Alpha"; echo "但 {$Alpha}es是 {$Omega}es的 呜呜呜/(ㄒoㄒ)/~~ <br>"; // 预定义常量 目录分割符 // echo DIRECTORY_SEPARATOR; // 魔术常量 // echo __DIR__.'\\ 0805\\demo1.php'; // require __DIR__.'\\..\\0805\\demo1.php' ; // require 'D:\phpstudy_pro\WWW\songyirui\0805\demo1.php'; echo __FILE__; echo __LINE__; // 定界符定义字符串 解析转义符 解析变量 比较适合输出大量的多行的内部存在多个变量的PHP字符串 echo <<<UI <table border="1" cellspacing="0" bgColor="pink"> <tr> <th>Omega<th><td>{$Omega}</td> <th>Alpha<th><td>{$Alpha}</td> </tr> </table> UI; ?>
<?php $str = 'watch'; // echo $str[3]; // echo $str{3};//报错 // $str{1} = 'w'; // echo $str;//Fatal error: Array and string offset access syntax with curly braces is no longer supported in D:\phpstudy_pro\WWW\songyirui\0809\demo2.php on line 6 $name = '张三'; // echo $name{0}.$name{1}.$name{2};//Fatal error: Array and string offset access syntax with curly braces is no longer supported in D:\phpstudy_pro\WWW\songyirui\0809\demo3.php on line 10 $name = '张三'; echo substr($name, 0, 1) . substr($name, 1, 1) . substr($name, 2, 1); // 输出 "张" echo $name;//直接输出整个字符串 "张三" // // 生成颜色随机 内容随机 字数4位的验证码 (/(ㄒoㄒ)/~~花括号有毒) // $codes = // 'hjfdjikjhuikjjkjkmjkmrssodewsxcvbgfjcx,woeiruyEDJUGIRKEOL1234567890'; // // 获取随机索引 // // echo mt_rand(0,strlen($codes)-1); // // echo $codes{mt_rand(0,strlen($codes)-1)};//Fatal error: Array and string offset access syntax with curly braces is no longer supported in D:\phpstudy_pro\WWW\songyirui\0809\demo2.php on line 22 // $code = ''; // for ($i=0; $i < 4; $i++){ // $code .= $codes{mt_rand(0,strlen($codes)-1)};//Fatal error: Array and string offset access syntax with curly braces is no longer supported in D:\phpstudy_pro\WWW\songyirui\0809\demo2.php on line 25 // } // echo $code; // 生成颜色随机 内容随机 字数4位的验证码 $codes = 'hjfdjikjhuikjjkjkmjkmrssodewsxcvbgfjcx,woeiruyEDJUGIRKEOL1234567890'; // 获取随机索引 // echo mt_rand(0,strlen($codes)-1); // echo $codes[mt_rand(0,strlen($codes)-1)]; $code = ''; for ($i=0; $i < 4; $i++){ $code .= $codes[mt_rand(0,strlen($codes)-1)]; } echo $code; echo '<hr>'; // 生成颜色随机 内容随机 字数4位的验证码 $codes ='hjfdjikjhuikjjkjkmjkmrssodewsxcvbgfjcxwoeiruyEDJUGIRKEOL1234567890'; $code = ''; for ($i = 0; $i < 4; $i++){ // 随机颜色rgb([参数0-255]) $code .= '<span style="color:rgb( '.mt_rand(0,255).','.mt_rand(0,255).','.mt_rand(0,255).')" > '. $codes[mt_rand(0,strlen($codes)-1)]. '</span>' ; } echo $code; echo '<hr>'; // strcmp($string1,$string2):比较两个字符串的大小 区分大小写 验证用户密码是否一致 一致返回0 if(strcmp('xixi','xixi') !==0) { echo json_encode(['status'=>0,'msg'=>'两次密码须一致'],320); }else{ echo json_encode(['status'=>1,'msg'=>'密码确认通过'],320); } echo '<hr>'; // strcasecmp($string1,$string2):忽略大小写 比较字符串的大小 验证码的验证 echo strcasecmp('412D','412d'); // ?>
<?php // implode|join($delimiter,$array):以指定分割符将数组中的键值连接成字符串 // implode|join数组转字符串 $course = ['html','css','js','vue','uniapp']; echo implode(",",$course); echo '<hr>'; // 字符串转数组explode($delimiter,$string):将指定字符串拆分成数组 $res = explode(',','html,css,js,vue,uniapp'); print_r($res); // 字符串截取 substr($string,$start[,$length]):截取字符串 // echo md5(rand());/ echo '<hr>'; $str = md5(rand()); echo $str; echo '<hr>'; echo substr($str,0,4); $color = '#'.substr($str,0,4); ?> <P style="color:<?=$color?>">你好</P> <?php // 需求 限制用户的用户名首个字符必须是字母 不能是数字等 // ord($char)://得到指定字符的ASCII echo ord('o'); $username = 'admin'; echo ucfirst($username).'<hr>'; echo ord ($username); $username = '2dmin'; $username = ucfirst($username).'<hr>';//Admin echo ord ($username); if(ord($username)<65 ||ord($username)>90) { echo'用户首字母必须是字母'; } //chr()根据ASCII得到指定的字符 echo chr(90); ?>
<?php // 字符串代替函数str_replace($search,$replace,$string):在指定字符串中查找另外一个字符串,找到之后将其替换成指定字符串 // echo DIRECTORY_SEPARATOR; $path = "D:\phpstudy_pro\Extensions\php\php7.3.4nts"; echo str_replace('\\','/',$path); echo str_replace('转账','--','你可以转账到我的支付宝或者转账到微信',$count); echo '\'转账\'被替换了'.$count.'次'; $search = ['睡觉','起床','洗漱','做饭','学习','电影','漫画']; $flag = ['@@','%%','**','##','…………','__','$#']; $news = '嘻嘻小茗昨天和姐姐睡觉睡到很早,所以今天起床,早早,洗漱做饭看电影,上班的路上看会漫画'; echo str_replace($search,$flag,$news); ?>
<?php // base64_encode()使用MIME base64对二进制数据进行编码 编码只有晗{A-Z a-z 0-9 + =} // 这64个字符串 = 用于填充 // header('Content-type:image/jpeg'); $file = file_get_contents('1.jpg'); // echo $file; $img_64 = base64_encode($file); echo $img_64; ?> <img src="data:image/jpeg;base64,<?=$img_64?>" alt="天仙">
标签:username,__,函数库,echo,经典,字符串,Alpha,string From: https://www.cnblogs.com/QWD7986/p/18286992