chop 是rtrim()的別名;

ltrim()

trim()

nl2br()將/n轉換成<br>

print,echo,printf(),sprintf():

echo()不是函數,print()是函數,有返回值,boolen,false,true;

printf()格式化輸出

--函數,把文字 " /> 老头操美女,五月丁香婷姐色,免费小视频在线观看

天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

php 常用字符串函數總結

1.格式化輸出

chop 是rtrim()的別名;

ltrim()

trim()

nl2br()將/n轉換成<br>

print,echo,printf(),sprintf():

echo()不是函數,print()是函數,有返回值,boolen,false,true;

printf()格式化輸出

--函數,把文字格式化以后輸出,直接調用系統調用進行IO的,他是非緩沖的。如:
$name="hunte";
$age=25;
printf("my name is %s, age %d", $name, $age);

sprintf()格式化字符串,然后賦給一個變量,但是不輸出,類似于c了

<?php
echo nl2br("foo isn't/n bar");
echo "foo isn't/n bar";
?>

--跟printf相似,但不打印,而是返回格式化后的文字,其他的與printf一樣。如:
char sql[256];
sprintf(sql,"select * from table where no = '%s'",bankno);
它的功能只是把""里面的語句賦給了變量sql。

strtolower

strtoupper

ucwords

ucfirst

2.字符串的連接和分割

(1)array explode(string input ,string separator , int limit)

使用一個字符串分割另一個字符串

<?php
// 示例 1
$pizza  = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode(" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2

// 示例 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *

?>  


例子 2. limit 參數示例

<?php
$str = 'one|two|three|four';

// 正數的 limit
print_r(explode('|', $str, 2));

// 負數的 limit
print_r(explode('|', $str, -1));
?>  



string strtok( string input ,string separator)

<?php
$string = "This is/tan example/nstring";
/* Use tab and newline as tokenizing characters as well          */
$tok = strtok($string, " /n/t");

//拿著空格,/n,/t作為令牌分割字符串

while ($tok !== false) {
            echo "Word=$tok<br />";
            $tok = strtok(" /n/t");
}
?>

結果:

Word=This
Word=is
Word=an
Word=example
Word=string

(2.)字符串的截取

$test="Your customer service is excellent";
echo substr($test,1);////////our customer service is excellent
echo "<br>";
echo substr($test,-9);//////從末尾起長度是9excellent
echo "<br>";
echo substr($test,0,4);////從0位置開始長度是4Your
echo "<br>";
echo substr($test,5,-13);/從第四個開始到倒數第13個字符customer service
echo "<br>";

$test="Your customer service is excellent";
echo substr($test,1);
echo "<br>";
echo substr($test,-11);
echo "<br>";
echo substr($test,0,6);
echo "<br>";
echo substr($test,5,-13);
echo "<br>";

our customer service is excellent
s excellent
Your c
customer service

(3)join()字符串的鏈接

3.字符串的查找


(1)string strstr ( string haystack, string needle ) 別名:strchr,stristr和strstr類似不同在于不區分大小寫

strrchr()相反的,查找的是最后一次出現的字符串

第一次出現起的字符串
<?php
$email = '[email protected]';
$domain = strstr($email, '@');
echo $domain; // prints @example.com
?> 
$email = '[email protected]';
$domain =strstr($email,'e');
$domain2 =strrchr($email,'e');//最后一次出現起的字符串
echo $domain; 
echo "<br>";
echo $domain2;

[email protected]
e.com

(2)查找位置

int strpos(string str,string needle,[int offset]) 沒有找到返回的是false

返回從offset開始在str中查找needle的位置

$eg:$t-'hello world';

       echo strpos($t,'o',5);

     //7 從第o開始,查找o這個變量的位置,結果為7

int strrpos()

5.替換

str_replace("%body%","blank","<body text='%body%'")






6 。大寫小問題


Strpos
查找字符串中第一次出現的字符串的位置

Strrpos
查找字符串中某字符,繼第一次之后的最先出現的位置。

strpos(stripos無大小寫)
strrpos(strripos無大小寫)






strstr
stristr(無大小寫)

str_replace 
str_ireplace(無大小寫)

php技術php 常用字符串函數總結,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 午夜免费无码福利视频麻豆 | 成人性生交片无码免费看 | 一个人在线观看免费高清视频 | 丰满饥渴老太性hd | 国产盗摄一区二区三区 | 在线国内自拍精品视频 | 亚洲综合久久一本伊伊区 | 大学生高潮无套内谢视频 | 白洁在线观看 | 色一欲一性一乱一区二区三区 | 亚洲野狼综合网站 | 瑜伽牲交AV | 成人国内精品久久久久影院 | 伊人久久亚洲精品一区 | 国产在线精品国自产拍影院午夜 | 国产亚洲精品久久久999密臂 | 动漫美女性侵 | 中文字幕在线不卡日本v二区 | 男人被绑着强行摸j | 91夫妻交友论坛 | 亚州日韩精品AV片无码中文 | 久久久久久久尹人综合网亚洲 | 忘忧草在线影院WWW日本动漫 | 美女穿丝袜被狂躁动态图 | 亚洲 日韩 国产 制服 在线 | 摸老师丝袜小内内摸出水 | 亚洲无遮挡 | 亚洲精品一线二线三线无人区 | 久久久国产精品免费A片3D | 久久精品国产欧美成人 | 中文字幕乱码亚洲无线三区 | 久久综合色超碰人人 | 中文人妻熟妇精品乱又伧 | 欧美黑人巨大性极品hd欧 | 国产免费人成在线视频视频 | 久久久久999 | 亚洲理论在线a中文字幕 | 亚洲另类欧美综合在线 | 久久一级视频 | 免费在线视频成人 | 夜色女人香 |