PHP Preg 替换之间的行

标签 php mysql

<p>Inspection and treatment will be conducted to areas prone to Mouse infestation by our Service Specialist during the routine visits. This includes the sewerage system servicing the property.</p>

<p>Apart from treating the sewerage manhole, application of residual coat will also be done at strategic areas prone to Mouse activity/harborages, and when necessary, baits will be placed and application of gel will be carried out.</p>

<p>Preparations used are safe to humans and animals and is approved by the Ministry.</p>

上面是我要记录到mysql中的文本,我想将它们修剪成

<p>Inspection and treatment will be conducted to areas prone to Mouse infestation by our Service Specialist during the routine visits. This includes the sewerage system servicing the property.</p><p>Apart from treating the sewerage manhole, application of residual coat will also be done at strategic areas prone to Mouse activity/harborages, and when necessary, baits will be placed and application of gel will be carried out.</p><p>Preparations used are safe to humans and animals and is approved by the Ministry.</p>

我使用了以下代码:

$service_desc = preg_replace('/\s+/', ' ', $service_desc);

但是代码没有解决字符串文本之间的间距问题,如何删除之间的空白以获得我想要的结果。

谢谢!

最佳答案

如果你想删除行尾字符,这不是更容易吗?

$service_desc = str_replace("\r\n", '', $service_desc);

$service_desc = str_replace("\n", '', $service_desc);

抱歉,如果这不是您所要求的。

关于PHP Preg 替换之间的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34608096/

相关文章:

php - 在一段时间后刷新 PHP Mysqli 查询,for 循环?

mysql - SQL:选择属于所有指定流派的所有电影

mysql - Delphi Mysql存储过程单引号问题

php - 高分 PHP SQL

php - 如何使用 php 从 mysql 表中删除超过 30 分钟或 24 小时的数据

php - 在 wordpress 插件中的表中添加另一列

php - 如何在PHP中获取针后的字符串?

php - Swiftmailer 发送后删除附件

php - Laravel 5.4 将 json 保存到数据库

php - 如何将每个用户的购物车订单插入数据库中的一列(而不是行)?