开发者

how to keep some characters using preg_replace

I have this php code

$audio_name=preg_replace('/[&#].*[;]/','',$audio['name'][1][$i]);
开发者_JAVA百科

but i want to keep the French characters


You can use preg_replace_callback, in the callback you can return '' if you want to remove the element and return the matched element if you want to keep it.

Note: .* is greedy and will eat everything till the last ;, so use [^;]*.


for example, replacing AAAAAAAA with BBBBBBBB:

$string= 'start AAAAAAAA end';
echo preg_replace('/(start)(.*?)(end)/i', (!empty('$1') ? '$1' : '').'BBBBBBBB'.(!empty('$2') ? '$2' : '') , $string);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜