Php使用1个固定字符和2个随机数爆炸 [英] Php explode using 1 fixed character and 2 random numbers

查看:72
本文介绍了Php使用1个固定字符和2个随机数爆炸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个任务,该任务将从xml文件读取,然后将信息存储到数据库.在此过程中,它会删除不必要的信息,并更改其他部分.

I have created a task that will read from an xml file, and then store information to a database. During the process it strips out unnecessary information, and changing other parts.

读取XML文件时,我得到如下信息:

When reading the XML file, I get information as follows:

<time>2/1/2016 16:49:15</time>
<type>GOALS</type>
<event>FC HALIFAX TOWN 2-2 Lincoln City</event>

处理事件"时我陷入困境.

I am getting stuck when working with the 'event'.

我想爆炸事件,以便留下:

I want to explode the event, so that I am left with:

$team[0] = "FC HALIFAX TOWN"
$team[1] = "Lincoln City"

我不能使用'-',然后从$ team [0]中删除最后一个字符,并从$ team [1]中删除第一个字符,因为有些团队的名称中使用了'-',例如特拉维夫马卡比".

I can't use '-' and then remove the last character from $team[0] and the first character from $team[1] as there are some teams that use '-' in their name, such as 'Maccabi Tel-Aviv'.

所以我试图找到一种爆炸的方式,并且能够找到数字而不是字母.

So I am trying to find a way to explode and it being able to find the numbers, rather than letters.

任何人都可以提供帮助吗?

Anyone able to help?

推荐答案

由于匹配结果不同,我建议使用正则表达式和preg_split:

As match results are different, I suggest using regexps and preg_split:

$r = preg_split("/ (\d+)\-(\d)+ /", "FC HALIFAX TOWN 2-2 Lincoln City");
print_r($r); // outputs:  Array ( [0] => FC HALIFAX TOWN [1] => Lincoln City ) 

我在比赛结果周围特别加了空格,以使regexp更精确.

I specially added spaces around match results so as to make regexp more precise.

这篇关于Php使用1个固定字符和2个随机数爆炸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆