PHP单独的字符串部分

时间:2014-11-10 11:15:45

标签: php html css

$ekipa = "Admini-aruturek,Kura126"                      
$rangi = explode('-', $ekipa);
foreach ($rangi as $ranga){     #I know that is no correct.                 
    echo($ranga[1]);   #This is not correct!
    echo($ranga[2]);   #This is not correct!
}

好的,我想分开字符串的第一部分和第二部分。例如 ADMINI-aruturek,Kura126 至 ADMINI 和 aruturek,Kura126

从“Admini-aruturek,Kura126”到: echo“Admini”; 回声“aruturek,Kura126”

怎么做?

3 个答案:

答案 0 :(得分:0)

你可以获得像

这样的价值
<?php
$ekipa = "Admini-aruturek,Kura126"           ;           
$rangi = explode('-', $ekipa);

foreach ($rangi as $ranga){                         
   echo $ranga.'<br/>';
}
?>

答案 1 :(得分:0)

您需要获得$rangi数组的0和1索引尝试

$ekipa = "Admini-aruturek,Kura126";                   
$rangi = explode('-', $ekipa);
echo $rangi[0];//Admini
echo $rangi[1]; //aruturek,Kura126 

两者

echo $rangi[0].$rangi[1];

答案 2 :(得分:0)

这不是你的意思吗?你说团队名称是Admini,但是你说你想要和Kura126一起展示aruturek?

$ekipa = "Admini-aruturek,Kura126";                      
$rangi = explode(',', $ekipa);
foreach ($rangi as $ranga) {                 
    if (strstr($ranga, '-') !== false) {
        list($name, $name2) = explode('-', $range);
    } else {
        $name = $ranga;
    }
    echo $name . "<br/>";
}