PHP解析圣经书籍字符串时出现问题 [英] PHP problems parsing a bible book string

查看:79
本文介绍了PHP解析圣经书籍字符串时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望你能帮助我.

我有一个类似以下的字符串

I have a string like the following

路加福音1:26-38

Luke 1:26-38

我希望能够将其分解为令牌或单个变量,以便可以在SQL查询中使用这些变量.

And I would like to be able to break it up into tokens or individual variables so that I can use the variables in an SQL query.

我尝试使用爆炸,但是我只能使它在一个字符上爆炸,例如:或-

I've tried using explode, however I've only been able to make it explode on one character such as : or -

我的字符串具有:和-,并且名称和第一个数字之间还有一个空格.

My string has : and - and also a space between the name and the first number.

我的目标是拥有:

    $name = Luke;
    $book = 1;
    $from = 26;  
    $to = 38;

有人可以帮忙吗?

非常感谢

推荐答案

list( $name, $book, $from, $to ) = preg_split( '/[ :-]/', 'Luke 1:26-38' );

echo $name; //"Luke"

    /* Split results in an Array
(
    [0] => Luke
    [1] => 1
    [2] => 26
    [3] => 38
)
     */

这篇关于PHP解析圣经书籍字符串时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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