Blogger Information
Blog 18
fans 0
comment 0
visits 14913
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php 字符串函数
牛粪也香的博客
Original
860 people have browsed it

// ----------------------------------字符串---------------------------------------------

echo "<hr>";

echo "<hr>";

$str='abcdef';

echo $str{0};

echo "<br/>";

echo $str{3}."<br/>";


$str{1}="k";


echo $str;

echo "<hr>";

//若是中文,中文在UTF8下占三个字符


$str="你好";

echo $str{0};

echo $str{1};

echo $str{2};//三个连续输出才以显示

echo "<hr>";

$str='abc';

$str{0}='null';

echo $str;

var_dump($str);


//增加

$str="abc";

$str{3}='d';

echo $str;

var_dump($str);


function code($len){

//验证码。

$str="abcdeftghijklmnopqrstuvwxyz";

$str.=strtoupper($str);

$str.='0123456789';

$checkcode='';

for ($i=1;$i<=$len;$i++){

  $checkcode.=$str{mt_rand(0,strlen($str)-1)};

}

return $checkcode;

}


echo code(5);

echo "<hr>";

// 定界符

// heredoc语法结构:

// <<<标识名称

//     内容


//     标识名称;

// 标识名称,以字母下划线等开始,

// //可以不有再管相关的字符了

echo "heredoc";

$username="wwkakak";

$table=<<<EOF

<table border='1px' width='80%' align='center'>

<tr><td>1111</td><td>2222</td><td>3333333</td></tr>

<tr><td>1111</td><td>2222</td><td>3333333</td></tr>

<tr><td>1111</td><td>2222{$username}</td><td>33ip"ss"'3'3'333</td></tr>


</table>


EOF;

echo $table;


echo <<<eof

    hello baby

eof;


//nowdoc语法结构和heredoc语法结构一样,只是有单引号的作用

echo '<hr/>';

echo 'nowdoc<br/>';


$str=<<<'eof'

helle $username;

eof;

echo $str;

echo "<br/>字符串类型的转换";

echo 123;

echo '<br/>';

echo 34.5;

echo '<br/>';

echo true;

echo '<br/>';

echo 'a',false,'b';

echo 'c',null,'d';

echo '<br/>';

$array=array(12,3,4);

echo '<br/>';

echo $array;//$array 不能直接输出

echo '<br/>';

echo $array[0];

echo '<br/>';


$handle=fopen('func.php','r');

echo $handle;

echo '<br/>';

$obj=new stdClass();

var_dump($obj);

//echo $obj;

//Catchable fatal error: Object of class stdClass could not be converted to string in D:\wamp64\www\phpt\func.php on line 300

echo '<br/>';


$var=123;

$var=123.2;

$var=true;

$var=false;

$var=null;

$var=array(1,2,3);

$var=new stdClass();

//Catchable fatal error: Object of class stdClass could not be converted to string 

$var=fopen('func.php','r');

$res=(string)$var;

var_dump($var,$res);


//------------------------字符串函数库----------------------------------------

echo "字符串函数库<hr>";

$var='hello baby';


var_dump(is_string($var));

//检测字符串的长度

//strlen($var)

echo strlen($var);

echo '<br/>';

$res=strtoupper($var);

echo $res;

echo '<br/>';

$res=strtolower($var);

echo $res;

echo '<br/>';

//首字母大写

$res=ucfirst($var);

echo $res;

echo '<br/>';

//每个单词首字母大写

$res=ucwords($var);

echo $res;


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