Home > Backend Development > PHP Tutorial > 帮助写一个小正则,该怎么解决

帮助写一个小正则,该怎么解决

WBOY
Release: 2016-06-13 13:31:13
Original
835 people have browsed it

帮助写一个小正则
类似的数据格式为:0,37

72,5
要求把最后的72,5 匹配出来,php环境,谢谢!
(只要72,5,其他的数据都丢弃即可)

------解决方案--------------------
PHP code

$str    = '0,37
Copy after login
72,5'; preg_match("/.*?([\d]+,[\d]+)$/", $str, $m); echo $m[1]; ////72,5
------解决方案--------------------
PHP code
<?php $str='0,355</td><td class="Pdata">9500</td><td class="Pdata">11000</td><td class="Pdata">72,5</td>bla...';
preg_match_all('/(?:<td class="Pdata">(.*?))+/s',$str,$matchs);
echo $matchs[1][0];
<br><font color="#e78608">------解决方案--------------------</font><br><fieldset>
<legend>探讨</legend>
<br><br>72,5 可能是 0,355</fieldset>
</td><td class="Pdata">9500</td><td class="Pdata">11000</td><td class="Pdata">这样的格式<br>
<br><font color="#e78608">------解决方案--------------------</font><br><fieldset>
<legend>探讨</legend>
<br>这里哪有你前面说的72,5这样的格式呢?难道是0,355了?<br>
</fieldset>
<br><font color="#e78608">------解决方案--------------------</font><br>莫非这样?<br><br>试试差多少<br><dl class="code">PHP code<pre class="brush:php;toolbar:false">

preg_match("/.*>([\d,]+)/", $str, $m);
echo    $m[1];
<br><font color="#e78608">------解决方案--------------------</font><br>可以 的
<br><font color="#e78608">------解决方案--------------------</font><br>
Copy after login
探讨
$str = '0,37
72,5';

$kkk9 =split('[>]', $str);

用这种数组分割的方式 可以吗,取最后一个数组里的内容?
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