Home  >  Article  >  Backend Development  >  PHP---common codes

PHP---common codes

WBOY
WBOYOriginal
2016-08-08 09:24:41886browse

1. Delete the first character of the string:

<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. Define the page encoding format:

<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. Set the running time limit and browser closing limit:

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

4. Intercept the two strings Part

<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>

The above introduces PHP---commonly used codes, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn