在PHP中将段落分解为句子 [英] Explode a paragraph into sentences in PHP

查看:187
本文介绍了在PHP中将段落分解为句子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用

explode(".",$mystring)

将段落分为句子.但是,这不包括以不同标点符号结尾的句子,例如!! ? :;

to split a paragraph into sentences. However this doen't cover sentences that have been concluded with different punctuation such as ! ? : ;

是否有一种使用数组而不是单个字符作为分隔符的方法?另外,还有使用各种标点符号进行拆分的另一种巧妙方法吗?

Is there a way of using an array as a delimiter instead of a single character? Alternativly is there another neat way of splitting using various punctuation?

我尝试过

explode(("." || "?" || "!"),$mystring)

希望它没用...

推荐答案

您可以这样做:

preg_split('/\.|\?|!/',$mystring);

或(更简单):

preg_split('/[.?!]/',$mystring);

这篇关于在PHP中将段落分解为句子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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