需要从一个字符串中提取一个信息,该字符串是' type - '并以' -id'
结束IDlocationTagID-type-area-id-492
这是字符串,所以我需要从字符串中提取值:area和492:
'类型 - '之前' -id'在' id - '
之后答案 0 :(得分:2)
您可以使用preg_match: 例如:
preg_match("/type-(.\w+)-id-(.\d+)/", $input_line, $output_array);
要检查,您可能需要该服务:
P.S。如果函数preg_match太重,还有另一种解决方案:
$str = 'IDlocationTagID-type-area-id-492';
$itr = new ArrayIterator(explode('-', $str));
foreach($itr as $key => $value) {
if($value === 'type') {
$itr->next();
var_dump($itr->current());
}
if($value === 'id') {
$itr->next();
var_dump($itr->current());
}
}
答案 1 :(得分:1)
这就是你想要的两个爆炸。
SELECT COUNT(INVNO)
, INVNO
FROM INVOICE
GROUP BY INVNO
HAVING COUNT(INVNO) > 1
ORDER BY INVNO
SELECT DISTINCT invno
FROM INVOICE
ORDER BY INVNO
简单的方法。
$str = 'IDlocationTagID-type-area-id-492';
echo explode("-id", explode("type-", $str)[1])[0]; //area
echo trim(explode("-id", explode("type-", $str)[1])[1], '-'); //492
使用正则表达式:
echo explode("type-", explode("-id-", $str)[0])[1]; // area
echo explode("-id-", $str)[1]; // 492
答案 2 :(得分:1)
您可以使用explode来获取值:
$a = "IDlocationTagID-type-area-id-492";
$data = explode("-",$a);
echo "Area ".$data[2]." Id ".$data[4];
答案 3 :(得分:0)
$matches = null;
$returnValue = preg_match('/type-(.*?)-id/', $yourString, $matches);
echo($matches[1]);