Blogger Information
Blog 38
fans 0
comment 1
visits 30416
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1. 数组排序方法总结 2. 字符串长度计算 3. 字符串与数组之间的转换 4. 字符串的查找与替换
1
Original
565 people have browsed it

1.

实例

<meta charset="utf-8">
<?php 
echo '<pre>';
$arr = [3,5,4,10,'a'=>'jojo',39,'mysql',true];
print_r($arr);
echo '<hr>';

// sort($arr);
 // sort($arr,SORT_NUMERIC);
 // sort($arr,SORT_STRING);
 // asort($arr);
 // asort($arr,SORT_NUMERIC);
 // asort($arr,SORT_STRING);
 // ksort($arr);
 // ksort($arr,SORT_NUMERIC);
 // ksort($arr,SORT_STRING);
 // rsort($arr);
 // rsort($arr,SORT_NUMERIC);
 // rsort($arr,SORT_STRING);
 // arsort($arr);
 // arsort($arr,SORT_NUMERIC);
 // arsort($arr,SORT_STRING);
 
usort($arr,function($a,$b){
		$res = $a - $b; 
	if ($res == 0) {
		return 0;
	} else if ($res > 0) {
		return true;
	} else {
		return false;
	}
})

print_r($arr);
 ?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

2.

实例

<meta charset="utf-8">
<?php 
$siteName = '1aa六朝云龙吟';
$encoding = mb_internal_encoding();
echo $encoding;
echo strlen($siteName);
echo mb_strlen($siteName);

 ?>

运行实例 »

点击 "运行实例" 按钮查看在线实例

3.

实例

<?php 
echo '转换';

echo '<pre>';
$str = 'html,css,jquery,php,mysql,thinkphp';
echo '<p>原始字符串:'.$str.'</p>';

print_r(explode(',',$str)); //用','号进行分割字符串
print_r(explode(',',$str,5)); //指定数组必须是5个元素,最后一个元素保存全部剩余数据

$arr2 = explode(',', $str);
echo implode(' ', $arr2), '<br>'; //用空格分隔
echo implode(',',$arr2), '<br>'; //用,分隔
echo implode('--',$arr2), '<br>'; //用--分隔

运行实例 »

点击 "运行实例" 按钮查看在线实例

4.

实例

<?php 
echo '<p>字符串函数(六):查找与替换</p><hr color="green">';

$str = 'www.php.cn';
//1.strpos($str,$needle, $offset)查找字符串首次出现的位置
echo strpos($str, 'p'),'<br>'; //默认从头开始查找
echo strpos($str, 'p', 5),'<br>'; //从索引5开始查找

//2.strstr($str1, $str2),如果$str2是$str1的子串,返回子串,返回否则false
echo strstr($str, 'php'),'<br>';  //返回子串及后面部分
echo strstr($str, 'php', true),'<br>'; //参数true,会返回子串前面部分

echo '<hr>';
//3.str_replace($str1, $str2, $str3, $num):子串替换,
echo str_replace('www','http://www',$str), '<br>';

echo '<hr>';
//4.substr_replace($str1,$str2,$str3,$start, $length):替换字符串的子串
//在$str中,从第5个索引位置起的2个字符,用'pppph'进行替换
echo substr_replace($str,'pppph', 5, 2);

运行实例 »

点击 "运行实例" 按钮查看在线实例


Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
  • 1
    2018-03-16 00:39:40
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!