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教學有興趣的朋友有幫助。