In PHP, the definition of a string can use English single quotes ' ' or English double quotes " ". However, PHP allows us to include string variables directly within double-quoted strings. The content in single quote strings is always considered to be ordinary characters.
<code><span>$str</span>=<span>'hello'</span>; <span>echo</span><span>"str is <span>$str</span>"</span>; //运行结果: str is hello <span>echo</span><span>'str is $str'</span>; //运行结果: str is <span>$str</span></code>
Use English dots in PHP to connect two strings.
<code><span><span><?php</span><span>$i</span>=<span>'I'</span>; <span>$love</span>=<span>' Love'</span>; <span>$you</span>=<span>' You'</span>; <span>//连接一下三个字符串</span><span>echo</span><span>$i</span>.<span>$love</span>.<span>$you</span>; <span>?></span></span></code>
Remove spaces from the beginning and end of a string
There are three functions in PHP that can remove spaces from a string
trim removes spaces from both ends of a string.
rtrim is to remove the spaces on the right side of a string, where r is the abbreviation of right.
ltrim removes spaces from the left of a string, where l is the abbreviation of left.
<code><span><span><span><?php</span><span>//</span><span>$str</span>=<span>" 空格要去掉 "</span>; <span>echo</span><span>"jar"</span>.trim(<span>$str</span>).<span>"len"</span>.<span>"<br>"</span>; <span>echo</span><span>"jar"</span>.ltrim(<span>$str</span>).<span>"len"</span>.<span>"<br>"</span>; <span>echo</span><span>"jar"</span>.rtrim(<span>$str</span>).<span>"len"</span>.<span>"<br>"</span>; <span>?></span></span></span></code>
Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the mobile app interface programming technology - learning to implement PHP strings, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.