【问题标题】:Split/Explode in String identifying only the first element (Symbol or Word)?在字符串中拆分/分解仅识别第一个元素(符号或单词)?
【发布时间】:2014-12-08 04:18:42
【问题描述】:

我有下一个字符串:

String = "Name: James, Training, Physician, Hobbies: Sports, Reading, Age: 24".

将以下字符串与仅找到的第一个 ':' 共享,进行以下操作:

stringsplit1 = "Name";
stringsplit2 = "James, Training, Physician, Hobbies: Sports, Reading, Age: 24";

或在数组中。 :S

【问题讨论】:

  • 你的explode()在哪里?
  • 你应该可以用explode()的第三个参数来做到这一点

标签: php string split explode


【解决方案1】:

explode()

explode(':',$string,2);
                    ^ ------------> limit [int]

完整代码:

$string = "Name: James, Training, Physician, Hobbies: Sports, Reading, Age: 24";
$ar = explode(":",$string,2);
print_r($ar);

【讨论】:

    猜你喜欢
    • 2020-07-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 2012-08-27
    • 1970-01-01
    相关资源
    最近更新 更多