验证逗号分隔列表但以“&”和单词结尾的正则表达式是什么 - php

我可以提取到11.20,但是之后逗号停止并且我编写的正则表达式失败。我怎么写这个表达式?我正在使用preg_match_all函数。

输入字符串:

8, 8.40, 9.20, 10, 10.40, 11.20, 12 & 12.40 latenight

需要的输出:

Array
    (

        [0] =>  8,
        [1] =>  8.40,
        [2] =>  9.20,
        [3] =>  10,
        [4] =>  10.40,
        [5] =>  11.20,
        [6] =>  12,
        [7] =>  12.40,
    )

参考方案

$string = '8, 8.40, 9.20, 10, 10.40, 11.20, 12 & 12.40 latenight';
$string = str_replace('&', ',', $string);
$string = str_replace(' ', ',', $string);

$parts  = preg_split('/,+/', $string);

print_r($parts);

版画

Array
(
    [0] => 8
    [1] => 8.40
    [2] => 9.20
    [3] => 10
    [4] => 10.40
    [5] => 11.20
    [6] => 12
    [7] => 12.40
    [8] => latenight
)

足够近?

php Singleton类实例将在多个会话中保留吗? - php

举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…

PHP:对数组排序 - php

请如何排序以下数组Array ( 'ben' => 1.0, 'ken' => 2.0, 'sam' => 1.5 ) 至Array ( 'ken' => 2.0, 'sam' => 1.5, 'ben' =&…

PHP strtotime困境 - php

有人可以解释为什么这在我的服务器上输出为true吗?date_default_timezone_set('Europe/Bucharest'); var_dump( strtotime('29.03.2015 03:00', time()) === strtotime('29.03.2015 04:00�…

PHP-全局变量的性能和内存问题 - php

假设情况:我在php中运行一个复杂的站点,并且我使用了很多全局变量。我可以将变量存储在现有的全局范围内,例如$_REQUEST['userInfo'],$_REQUEST['foo']和$_REQUEST['bar']等,然后将许多不同的内容放入请求范围内(这将是适当的用法,因为这些数据指的是要求自…

php-casperjs获取内部文本 - php

我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…