复杂的preg_replace()

时间:2018-04-26 17:12:47

标签: php regex

有没有办法将此代码转换为单行preg_replace()以避免重复代码?提前谢谢。

$string = preg_replace('/[^ \w]+\'/', ' ', $string); // Removes special chars except spaces and single quote.
$string = preg_replace('/\'/', '!', $string); //Replace single quotes to exclamation
$string = preg_replace('/-/', '^', $string);
$string = str_replace(' ', '-', $string); //Change spaces to -
$string = preg_replace('/\s\s+/', '!-', $string)

0 个答案:

没有答案