1. 문자열 길이를 가져옵니다.
<code><span>$str</span> = <span>'abc'</span>; <span>$str1</span>=<span>'中文'</span>; <span>echo</span> strlen(<span>$str</span>),<span>'<br/>'</span>,strlen(<span>$str1</span>); 输出结果: <span>3</span><span>6</span></code>
2. 문자열을 찾습니다.
<code>//查找字符串首次出现的位置 <span>$char</span> = <span>'a'</span>; <span>$str</span> = <span>'abc'</span>; <span>$bRet</span> = strpos(<span>$str</span>,<span>$char</span>); <span>if</span>(<span>$bRet</span> === <span>false</span>) { <span>echo</span><span>"<span>$str</span> 中不含有<span>$char</span> "</span>; }<span>else</span> { <span>echo</span><span>"<span>$str</span> 中含有<span>$char</span> "</span>; } <span>echo</span><span>'<br />'</span>; 输出结果: abc 中含有a </code>
3. 문자열을 바꿉니다. , 문자열
<code><span>//替换字符串str_replace()</span><span>$str</span> = <span>'Good morning'</span>; <span>$str1</span> = str_replace(<span>'moring'</span>,<span>'afternoon'</span>,<span>$str</span>); <span>echo</span><span>$str</span>, <span>'<br/>'</span>, <span>$str1</span>; 输出结果: Good morning Good morning <span>//替换字符串strtr()</span><span>$str</span> = <span>'上车,上课,上班,下车,下课,下班'</span>; <span>$str1</span> = strtr(<span>$str</span>,[<span>'上'</span>=><span>'下'</span>,<span>'下'</span>=><span>'上'</span>]); <span>echo</span><span>$str</span>,<span>'<br / >'</span>,<span>$str1</span>; 输出结果: 上车,上课,上班,下车,下课,下班 下车,下课,下班,上车,上课,上班</code>
을 차단합니다. 5. 문자열 분할
<code><span>//截取字符串substr(),参数分别为目标字符串,起始位置,截取长度</span><span>$str</span> = <span>'East,west,home is best'</span>; <span>echo</span><span>$str</span>,<span>'<br/>'</span>,substr(<span>$str</span>,<span>0</span>,<span>4</span>); 输出结果: East,west,home is best East</code>
6. 배열을 문자열
<code><span>//拆分字符串explode()</span><span>$str</span> = <span>'厨子, 戏子, 痞子'</span>; <span>$arr</span> = explode(<span>','</span>,<span>$str</span>); <span>echo</span><span>$str</span>,<span>'<br/>'</span>; print_r(<span>$arr</span>); 输出结果: 厨子, 戏子, 痞子 <span>Array</span> ( [<span>0</span>] => 厨子 [<span>1</span>] => 戏子 [<span>2</span>] => 痞子 )</code>
').addClass(' pre-numbering'으로 병합합니다. ).숨다(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i
').text(i)); }; $numbering.fadeIn(1700); }); });<code><span>$arr</span>=[<span>'0'</span>=><span>'厨子'</span>,<span>'1'</span>=><span>'戏子'</span>,<span>'2'</span>=><span>'痞子'</span>]; <span>$str</span>=implode(<span>$arr</span>,<span>';'</span>); print_r(<span>$arr</span>); <span>echo</span><span>'<br/>'</span>; <span>echo</span><span>$str</span>; 输出结果: <span>Array</span> ( [<span>0</span>] => 厨子 [<span>1</span>] => 戏子 [<span>2</span>] => 痞子 ) 厨子;戏子;痞子</code>위 내용은 내용의 측면을 포함하여 PHP에서 문자열을 처리하는 방법을 소개합니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.