Determine whether it is a number, time format

WBOY
Release: 2016-07-29 09:05:59
Original
1045 people have browsed it

is_numeric();

<code><span><span><?php</span><span>$tests</span> = <span>array</span>(
    <span>"42"</span>, 
    <span>1337</span>, 
    <span>"1e4"</span>, 
    <span>"not numeric"</span>, 
    <span>array</span>(), 
    <span>9.1</span>
);

<span>foreach</span> (<span>$tests</span><span>as</span><span>$element</span>) {
    <span>if</span> (is_numeric(<span>$element</span>)) {
        <span>echo</span><span>"'{$element}' is numeric"</span>, PHP_EOL;
    } <span>else</span> {
        <span>echo</span><span>"'{$element}' is NOT numeric"</span>, PHP_EOL;
    }
}
<span>?></span></span></code>
Copy after login

result

<code><span>'42'</span><span>is</span> numeric
<span>'1337'</span><span>is</span> numeric
<span>'1e4'</span><span>is</span> numeric
<span>'not numeric'</span><span>is</span><span>NOT</span> numeric
<span>'Array'</span><span>is</span><span>NOT</span> numeric
<span>'9.1'</span><span>is</span> numeric</code>
Copy after login

strtotime($time)

<code><span>$time</span> = <span>'2015adsasd'</span>;
var_dump(strtotime(<span>$time</span>));
<span>$time1</span> = <span>'2015-01-11'</span>;
var_dump(strtotime(<span>$time1</span>));</code>
Copy after login

result

<code><span>bool</span>(<span>false</span>)
<span>int</span>()</code>
Copy after login
').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the judgment of whether it is a number and the time format, including the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!