Php 用单个分号替换任何重复的分号
在PHP中,用单个分号替换多个分号的最佳方法是什么Php 用单个分号替换任何重复的分号,php,regex,Php,Regex,在PHP中,用单个分号替换多个分号的最佳方法是什么 xyz;;;;zyx 将成为 xyz;zyx 如果您了解一点正则表达式,那么可以使用PHP函数轻松完成这项工作 <?php $text = 'dasd;;;;;;dasdd;;;da;sd;;;;;das;d;;;d;as;d;as;d;;;;;;;'; $replace = preg_replace('/;+/', ';', $text); var_dump($replace); // string(30) "dasdd
xyz;;;;zyx
将成为
xyz;zyx
如果您了解一点正则表达式,那么可以使用PHP函数轻松完成这项工作
<?php
$text = 'dasd;;;;;;dasdd;;;da;sd;;;;;das;d;;;d;as;d;as;d;;;;;;;';
$replace = preg_replace('/;+/', ';', $text);
var_dump($replace); // string(30) "dasddasddda;sddas;dd;as;d;as;d"
preg\u replace。也,