字符串函数学习(一)

header("Content-Type:text/html;charset=utf-8");
/*
$chars="abcdefghijklmnopqrstuvwxyz";
$letters=array(15,7,15);
foreach($letters as $letter)
{
	echo $chars{$letter};
}
//result:php

echo "abc"+123;
//result:123

echo "123"+123;
//result:246


$email='loki_wuxi@163.com';
echo substr($email,strpos($email,'@')+1);
//strpos():find '@' ,and return the index
//substr($strfindin.$start.$length)


$html='

这里是p标记的内容

网易'; echo strip_tags($html); //剥离html和php标记,第二个参数是要排除的标记 echo strcmp('loki','Loki');//loki is greater than Loki echo strcmp('loki','loki1');//loki is less than loki1 echo strcmp('字符串','字符串');//字符串 is equal with 字符串 //Binary safe string comparison //Pad a string to a certain length with another string //str_pad($input,$tolength,$char,$leftORrightORboth)default is right echo str_pad('loki',12,'ab',STR_PAD_BOTH); //result:abablokiabab echo str_pad('loki',12,'填补',STR_PAD_BOTH); //result:乱码 //split a string to an array whose element is 4 length or less echo var_dump(str_split('welcome to lokizone',4)); //result:array(5) { [0]=> string(4) "welc" [1]=> string(4) "ome " [2]=> string(4) "to l" [3]=> string(4) "okiz" [4]=> string(3) "one" } //wordwrap($splitedstr,$tolength,$splitchar,true|false:强制20个字符|不拆分单词) $text = "The quick brown fox jumped over the lazy dog."; $newtext = wordwrap($text, 20, "
/n"); echo $newtext; //result:包括/n换行符 //The quick brown fox
//jumped over the lazy
//dog. //substr($input,$replacement,$start,$length) $var = 'ABCDEFGH:/MNRPQR/'; echo "Original: $var
/n"; // These two examples replace all of $var with 'bob'. echo substr_replace($var, 'bob', 0) . "
/n"; echo substr_replace($var, 'bob', 0, strlen($var)) . "
/n"; // Insert 'bob' right at the beginning of $var. echo substr_replace($var, 'bob', 0, 0) . "
/n"; // These next two replace 'MNRPQR' in $var with 'bob'. echo substr_replace($var, 'bob', 10, -1) . "
/n"; echo substr_replace($var, 'bob', -7, -1) . "
/n"; // Delete 'MNRPQR' from $var. echo substr_replace($var, '', 10, -1) . "
/n"; //result:Original: ABCDEFGH:/MNRPQR/
//bob
//bob
//bobABCDEFGH:/MNRPQR/
//ABCDEFGH:/bob/
//ABCDEFGH:/bob/
//ABCDEFGH://
//第四个参数如果是负数,那么替换从第三个参数给出的index到第四个参数字符串给出的从末尾开始abs(index),如果是0,表示不替换,直接在此位置插入 */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值