码迷,mamicode.com
首页 > Web开发 > 详细

PHP字符串的用法

时间:2015-09-27 13:39:31      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

<?php

$str = ‘hello php java C# C++‘;
echo $str.‘<br>‘;

echo strpos($str,‘o‘).‘<br>‘; //‘o‘ ‘ph‘

$str1 = substr($str,2,3); //($str,2)
echo $str1.‘<br>‘;

$result1 = str_split($str,2);// ($str)=($str,1)
print_r($result1); //print array
echo ‘<br>‘;
$result2 = explode(‘ ‘,$str);
print_r($result2);

echo ‘<br>‘;
$num = 100;
$str2 = $str.‘<br>Objective-C ‘.$num; //OR: "$str<br>Objective-C $num";
echo $str2;

 

结果:

hello php java C# C++
4
llo
Array ( [0] => he [1] => ll [2] => o [3] => ph [4] => p [5] => ja [6] => va [7] => C [8] => # [9] => C+ [10] => + ) 
Array ( [0] => hello [1] => php [2] => java [3] => C# [4] => C++ ) 
hello php java C# C++
Objective-C 100

PHP字符串的用法

标签:

原文地址:http://www.cnblogs.com/htmlphp/p/4842125.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!