国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php replaces all symbols or spaces in the string with "-"
PHPz
PHPz 2017-05-16 13:16:12
0
3
697

How to replace all symbols or spaces in a string of words with "-"
Including,? @%! $&*(whatever)

PHPz
PHPz

學(xué)習(xí)是最好的投資!

reply all(3)
習(xí)慣沉默

$result = preg_replace('/[^w]|[_]/', '「-」', $str);
匹配替換非字母數(shù)字并替換。
w包括_,如果想一并替換掉,再添加上 |[_].


Reply to comment:
If you want to replace characters other than Chinese and English, change the pattern to the following form:
/[^bA-Za-zx{4e00}-x{9fa5}]/u /[^bA-Za-zx{4e00}-x{9fa5}]/u
b 表示空格;
u4e00-u9fa5是unicode里中文的表示法,但preg_replace不支持u的寫(xiě)法,可以使用 x{XXXX}來(lái)替代;
最后使用ub represents a space;

u4e00-u9fa5 is the representation of Chinese in unicode, but preg_replace does not support the writing method of u, you can use x{XXXX} code> instead; ??Finally use the u option to indicate that the utf-8 character set is used. ??
伊謝爾倫

Call removeXss()

迷茫

preg_replace is one method, here I provide another method, see the code below

    $str = 'hello %abc?11';
    $patten = array(
        '【',
        '】',
        '「',
        '?',
        '%',
        '&'
    );

    $rs = str_replace(' ','',str_replace($patten,'「-」',$str));
    echo $rs;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template