小白兔晒黑了

导航

 

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 2024-07-24 02:42  小白兔晒黑了  阅读(22)  评论(0)    收藏  举报