首頁  >  文章  >  後端開發  >  PHP---常用程式碼

PHP---常用程式碼

WBOY
WBOY原創
2016-08-08 09:24:41886瀏覽

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><</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>);</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