首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在PHP中把字符串切成不同的部分?

在PHP中把字符串切成不同的部分?
EN

Stack Overflow用户
提问于 2014-02-18 23:14:52
回答 6查看 136关注 0票数 0

我是PHP的新手,我需要根据值而不是字符数将字符串分割成特定的部分。

我听说过explode函数和子字符串,但我不知道如何使用它来实现我想要的。

我得到了一个输出字符串:

Name: example Email: e.g@example.com Website: http://examples.com/ Comment: this is where the comment goes, we can't use explode because there's lots of spaces here Another comment: this is another comment Some random info: this is more info...

为了美观起见,我想在单独的行中显示此信息。

有没有办法在一个特定的单词之后但在另一个特定的单词之前返回一个单词?

EN

Stack Overflow用户

发布于 2014-02-18 23:42:40

你可以拆分一个大写字母,假设你的标题总是以一个大写字母开头。

代码语言:javascript
复制
$text = "Name: example Email: e.g@example.com Website: http://examples.com/ Comment: this    is where the comment goes, we can't use explode because there's lots of spaces here Another comment: this is another comment Some random info: this is more info...";
$test = preg_split('/(?=[A-Z])/', $text);
foreach($test AS $line){
    echo $line."<br />";
}
票数 0
EN
查看全部 6 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21857863

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档