1

我有这个数组(无法更改):

Array
(
    [0] => AGUI vs CARI Hora 7:30 pm</span></p>PUERTO LA CRUZ</span></p>
    [1] => MAGA vs LEON Hora 7:30 pm</span></p>CARACAS</span></p>
    [2] => BRAV vs TIGR Hora 7:30 pm</span></p>MARACAY</span></p>
    [3] => TIBU vs CARD Hora 7:30 pm</span></p>BARQUISIMETO</span></p>
)

我需要拆分以分别获取值,例如:

[0] => AGUI vs CARI Hora 7:30 pm</span></p>PUERTO LA CRUZ</span></p>

我需要分成:

AGUI vs CARI
7:30 pm (I not need the word "Hora")
PUERTO LA CRUZ

我试图</span></p>用这个替换:

str_replace("</span></p>", "-", trim($the_string_var));

并清理更多的字符串,但它不起作用,任何人都可以给我一些关于这个算法的提示或想法吗?

4

2 回答 2

1

尽我所能;)

<?php
$str="AGUI vs CARI Hora 7:30 pm</span></p>PUERTO LA CRUZ</span></p>";
$str=str_replace(array(' vs ',' Hora ','</span></p>'),'XXX',$str);
$arr=explode('XXX',$str);
foreach ($arr as $key=>$value)
    if (empty($value))
        unset($arr[$key]);
print_r($arr); //If you want it seperately, then access it like $arr[0],$arr[1],...

输出 :

Array ( [0] => AGUI [1] => CARI [2] => 7:30 pm [3] => PUERTO LA CRUZ )
于 2013-10-25T14:30:14.013 回答
0

试试这个 :-

 $var =  AGUI vs CARI Hora 7:30 pm</span></p>PUERTO LA CRUZ</span></p>

 $fvar = explode('Hora',$var);
 $svar = explode('</span></p>',$fvar[1]);

 echo $fvar[0];   //contains AGUI vs CARI
 echo $svar[0];   //contains 7:30 pm
 echo $svar[1];   //PUERTO LA CRUZ
于 2013-10-25T14:31:51.970 回答