Php 将字符串拆分为子字符串

Php 将字符串拆分为子字符串,php,regex,arrays,string,split,Php,Regex,Arrays,String,Split,在用遗留PHP编写自动化脚本的过程中,我得到了以下字符串 string '<br /><select id="addid8231736" name="addid8231736" size="1" > <option value="" selected="true">Select an option</option> <option value="11518065" data-qty="5"> 11 - PKR11099.59</o

在用遗留PHP编写自动化脚本的过程中,我得到了以下字符串

string '<br /><select id="addid8231736" name="addid8231736" size="1" >
<option value="" selected="true">Select an option</option>
<option value="11518065" data-qty="5"> 11 - PKR11099.59</option>
<option value="11518063" data-qty="1"> 9 - PKR9850.00</option>' 
(length=246)
通过字符串标记

有人能帮我得到我想要的选择吗

谢谢你们所有人

更新

我尝试通过
explode(“
$string=Array”)将其分解
(
[0]=>11-PKR11099.59
[1] =>9-PKR9850.00
)
[1] =>阵列
(
[0] => 11
[1] => 9
)
[2] =>阵列
(
[0]=>PKR11099.59
[1] =>PKR9850.00
)
)

@CBroe没有让你明白“到目前为止,我已经成功地做到了这一点”-告诉我们你做了什么来做到这一点…我有一个小功能,可以将html标记串起来,如果它像一个符咒一样有帮助,我愿意发布它们,一个小请求(请解释正则表达式,以便我可以学习这门艺术),我怎么才能只拿到11号和9号的身份证呢?谢谢你help@NewBee数据位于
$matches
中,是一个常规的多维数组。例如,Id“11”是
$matches[1][0]
就像输出显示的那样…看到了..因为一个原因而感到困惑,我可以使用for循环表示已知数量的元素,但是我的字符串在不同的时间具有可变的项数,所以我认为正则表达式可能会给我一个通用的解决方案..我不确定我是否理解您的问题?您可以使用
计数($matches[1])
找出有多少个ID,这样你就可以知道在
for
循环中使用什么数字。或者,你可以只使用
foreach
循环,而不必关心有多少ID。尝试只提取“[1]=>数组([0]=>11[1]=>9)”我怎么做?
string 'Select an option 11 - PKR11099.59 9 - PKR9850.00' (length=48)
array (size=3)
  0 => string '<br/><select id="addid8231736" name="addid8231736" size="1"><option value="" selected="true">Select an option' (length=109)
  1 => string ' value="11518065" data-qty="5"> 11 - PKR11099.59' (length=48)
  2 => string ' value="11518063" data-qty="1"> 9 - PKR9850.00</option>' (length=55)
$string = <<<EOS
<br /><select id="addid8231736" name="addid8231736" size="1" >
<option value="" selected="true">Select an option</option>
<option value="11518065" data-qty="5"> 11 - PKR11099.59</option>
<option value="11518063" data-qty="1"> 9 - PKR9850.00</option>
EOS;
preg_match_all('~<option.*?>\s*(\d+)\s*-\s*(.*?)</option>~',$string,$matches);
Array
(
    [0] => Array
        (
            [0] => <option value="11518065" data-qty="5"> 11 - PKR11099.59</option>
            [1] => <option value="11518063" data-qty="1"> 9 - PKR9850.00</option>
        )

    [1] => Array
        (
            [0] => 11
            [1] => 9
        )

    [2] => Array
        (
            [0] => PKR11099.59
            [1] => PKR9850.00
        )

)