0 概述

<?php //例1-1 单引号字符串。 print 'I have gone to the store.'; print 'I\'ve gone to the store.'; print 'Would you pay $1.75 for 8 ounces of tap water? '; print 'In double-quoted strings,newline is represented by \n >'; //例1-2 双引号字符串。 print "I've gone to the store."; print "The sauce cost \$10.25."; $cost = "$10.25"; print "The sauce cost $cost."; print "The sauce cost \$\061\060.\x32\x35."; //例1-3 。用heredoc 定义多行字符串 print <<< END It's funny when signs say things like: Original "Root" Beer "Free" Gigt Shoes cleaned while "you" wait or have other misquoted words. END; print <<< END $cost END; // nowdoc print <<< 'END' $cost END; //例1-4 。更多heredoc 定义的例子 print <<< PARSLEY It's easy to grow fresh: Parsley Chives on your windowsill PARSLEY; // 可能会发生错误的代码 print <<< DOGS If you like pets,yell out:DOGS AND CATS ARE GREAT! DOGS; //例1-5 。用heredoc 定义的方式来输出HTML $remaining_cards= 1; if($remaining_cards > 0){ $url = '/deal.php'; $test = 'Deal More Cards'; } else { $url = '/new-game.php'; $test = 'Start a New Game'; } print <<< HTML There are <b>$remaining_cards</b> left. <p> <a href = "$url">$text</a> HTML; //例1-6 。连接heredoc 定义的字符串 $listItem = 'li列表'; $divClass = 'red'; $ulClass = 'green'; $html = <<< END <div class = "$divClass"> <ul class="$ulClass"> <li> END .$listItem . '</li></div>'; print $html; //例1-7 。取得字符串中个别字符 $neighbor = 'Hilda'; print $neighbor[3]; $neighbor = '昨夜星辰昨夜风'; print $neighbor[3]; ?>
PHP中大括号'{}'用法图文详解:https://www.php.cn/faq/398418.html
1 访问字符串
strpos()

<?php //1-8 用strpos()来查询子字符串 $_POST['email']='123456@我的邮箱.com'; if(strpos($_POST['email'],'@')=== false){ print 'There was no @ in the e-mail address'; }else{ print '找到了@,在字符串的第'.strpos($_POST['email'],'@').'位'; } ?>
2 提取子字符串
substr()
中文字符串的截取方式:https://www.jianshu.com/p/6f048ea1d4b8
php 扩展 下载地址 https://www.cnblogs.com/lihailin9073/p/11145795.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
2020-07-24 Laravel 文件上传
2017-07-24 权限系统 5个表