PHP - Preg替换模式替换/或&如有必要,有空间或没有空间

时间:2016-09-28 20:11:44

标签: php preg-match preg-match-all

preg_replace模式用/&替换为and有无空格?该模式应该能够取代以下所有示例:

This is J/J.This is J and J.

J/J, Y& S, and U / A are names.J and J, Y and S and U and A are names.

What does J /J or J & E mean?What does J and J or J and E mean?

1 个答案:

答案 0 :(得分:1)

试试这个:

<?php
   $text = "J/J, Y& S, and U / A are names.";
   $result = preg_replace('~[/&]~', ' and ', $text, -1);
   echo $result;