您可以使用str_replace函数来代替正则表达式。PHP函数str_replace可以接收数组作为参数,所以你可以试试这个:
$input = 'test:)test:)test:) :) test:p test';
$smileys = array( ':)', ':p' );
$smileys_with_spaces = array( ' :)', ' :p' );
$output = str_replace( $smileys_with_spaces, $smileys, $input ); // test:) :) -> test:):)
$output = str_replace( $smileys, $smileys_with_spaces, $input ); // test:):) -> test :) :)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
324 次 |
| 最近记录: |