试试这个,我使用正则表达式将变量提取到数组中。您可以使用 var_dump 查看结果。
$string = 'something here
<map name="map">
< area shape="circle" coords="34,210,3" alt="something 1" href="test.php?place=aaa&time=1" />
< area shape="circle" coords="34,220,3" alt="something2" href="test.php?place=bbb&time=2" />
< area shape="circle" coords="669,229,3" alt="some 8" href="test.php?place=bbb&time=3" />
</map>';
preg_match_all("/(\d+\,\d+\,\d+)/", $string, $coords);
preg_match_all("/place\=(.*)\&time\=(\d+)/i", $string, $place_time);
var_dump($place_time, $coords);
var_dump() 结果
array (size=3)
0 =>
array (size=3)
0 => string 'place=aaa&time=1' (length=16)
1 => string 'place=bbb&time=2' (length=16)
2 => string 'place=bbb&time=3' (length=16)
1 =>
array (size=3)
0 => string 'aaa' (length=3)
1 => string 'bbb' (length=3)
2 => string 'bbb' (length=3)
2 =>
array (size=3)
0 => string '1' (length=1)
1 => string '2' (length=1)
2 => string '3' (length=1)
array (size=2)
0 =>
array (size=3)
0 => string '34,210,3' (length=8)
1 => string '34,220,3' (length=8)
2 => string '669,229,3' (length=9)
1 =>
array (size=3)
0 => string '34,210,3' (length=8)
1 => string '34,220,3' (length=8)
2 => string '669,229,3' (length=9)
您可以通过数组/键访问上述示例中的信息:
echo $coords[1][0]; //return: 34,210,3
echo $place_time[1][0]; //return: aaa
echo $place_time[2][0]; //return: 1