小白兔晒黑了

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
统计
 

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];

?>
View Code
复制代码

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'],'@').'位';
}

?>
View Code
复制代码

2 提取子字符串

substr()

 

中文字符串的截取方式:https://www.jianshu.com/p/6f048ea1d4b8

php 扩展 下载地址 https://www.cnblogs.com/lihailin9073/p/11145795.html

 

 

posted on   小白兔晒黑了  阅读(12)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有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个表
 
点击右上角即可分享
微信分享提示