我在使用PHP修剪一些文本时遇到问题。我的文字看起来像那样:
$teams = "team1-team2"
我需要修剪它,所以我得到了第一个团队和第二个团队,我通过使用这段代码来实现:
$team1= substr($teams, 0, strpos($teams, "-"));
$team2= substr($teams, strpos($teams, '-') + 1);
但现在我有这样的事情:team1-team2-team3
我怎样才能修剪弦乐,以便像以前那样得到团队?
答案 0 :(得分:2)
您可以使用explode()功能。例如:
$teams = explode("-", "team1-team2-team3");
echo $teams[0]; // prints "team1"
echo $teams[1]; // prints "team2"
echo $teams[2]; // prints "team3"
答案 1 :(得分:0)
你使用php的“爆炸”功能和字符来爆炸字符串