我是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...
为了美观起见,我想在单独的行中显示此信息。
有没有办法在一个特定的单词之后但在另一个特定的单词之前返回一个单词?
发布于 2014-02-18 23:42:40
你可以拆分一个大写字母,假设你的标题总是以一个大写字母开头。
$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 />";
}https://stackoverflow.com/questions/21857863
复制相似问题