首页 >后端开发 >php教程 >PHP---常用代码

PHP---常用代码

WBOY
WBOY原创
2016-08-08 09:24:41908浏览

1、删除字符串的第一个字符:

<code><span>$string</span>=<span>''</span>;
<span>foreach</span>(<span>$array</span><span>as</span><span>$key</span> => <span>$value</span>){
    <span>$string</span> .= <span>",$value"</span>;
}
<span>$string</span> = substr(<span>$string</span>,<span>1</span>);</code>

2、定义页面编码格式:

<code><span>meta http<span>-equiv</span><span>=</span>content<span>-type</span> content<span>=</span><span>"text/html; charset=UTF-8"</span><span>></span><span>header</span>(<span>"Content-type:text/html;charset=utf-8"</span>);</span></code>

3、设置运行时间限制和浏览器关闭限制:

<code><span>set</span>_time_limit(<span>0</span>);
ignore_user_abort(<span>true</span>);</code>

4、截取两个字符串中的部份

<code><span><span>function</span><span>getStringMiddlePart</span><span>(<span>$str</span>,<span>$str_begain</span>,<span>$str_end</span>)</span>{</span><span>//请确保$str_begain在$str中的唯一性</span><span>$temp</span> = explode(<span>$str_begain</span>,<span>$str</span>);
    <span>if</span>(!<span>isset</span>(<span>$temp</span>[<span>1</span>])) <span>return</span><span>false</span>;
    <span>$temp</span> = explode(<span>$str_end</span>,<span>$temp</span>[<span>1</span>]);
    <span>return</span><span>$temp</span>[<span>0</span>];
}</code>

以上就介绍了PHP---常用代码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn