开发者

Terrible with regex

开发者 https://www.devze.com 2023-02-20 20:35 出处:网络
How can I make this regular expression replace spaces as well any non latin alpha numeric character? preg_replace(\'/[^a-zA-Z0-9\\s]/\', \'\', $title)

How can I make this regular expression replace spaces as well any non latin alpha numeric character?

preg_replace('/[^a-zA-Z0-9\s]/', '', $title)

T开发者_开发百科hanks a lot


[^...] matches anything but ....
\s matches spaces.

You don't want it to not match spaces.


Everything looks ok, you just have to assing it to a variable!

$title = preg_replace('/[^a-zA-Z0-9\s]/', '', $title)


I would just do:

<?php
preg_match_all('/[a-zA-Z0-9\s]/', $title, $out);
$ntitle = implode($out,'');
?>

EDIT: Briedis is right though, your regex works fine.

0

精彩评论

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