我注意到 PHPis_numeric()接受“E”作为数字。我有一个字符串:“ 88205052E00”,我希望结果是:NOT numeric。
这是我测试的代码。
<?php
$notnumber = '88205052E00';
if(is_numeric($notnumber)) {
echo $notnumber . ' is a number';
} else {
echo $notnumber . ' is NOT a number';
}
?>
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了结果:
88205052E00 is a number
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到结果:88205052E00 is NOT a number?
我需要从下面的html代码中获取h2和h3标签为PHP中的$ var:
<div class="main-info">
<img class="iphone-img" alt="" src="https://www.myweb.com/securedImage.jsp">
<div class="sub-info">
<h2 class="model">iPhone 4S</h2>
<h3 class="capacity color">16GB Black</h3>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想要这个结果:
echo $model; // Should echo: 'iPhone 4S'
echo $capacitycolour; // Should echo: '16GB Black'
Run Code Online (Sandbox Code Playgroud)
我试图用preg_match,preg_match_all和getElementsByTagName但至今没有运气.
这是我试过的代码:
$pattern = '/[^\n]h2*[^\n]*/';
preg_match_all($pattern,$data, $matches, PREG_OFFSET_CAPTURE);
var_dump($matches);
Run Code Online (Sandbox Code Playgroud)
和:
$doc = new DOMDocument();
$doc->loadHTML($data);
$tags = $doc->getElementsByTagName('sub-info');
$root = $doc->documentElement;
foreach($root->childNodes as $node){
$attributes[$node->nodeName] = $node->nodeValue;
}
var_dump($attributes);
Run Code Online (Sandbox Code Playgroud)