Rapture
Rapture

Reputation: 1896

Terrible with regex

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)

Thanks a lot

Upvotes: 2

Views: 79

Answers (3)

Jess
Jess

Reputation: 8700

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.

Upvotes: 1

Mārtiņš Briedis
Mārtiņš Briedis

Reputation: 17762

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

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

Upvotes: 3

SLaks
SLaks

Reputation: 887777

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

You don't want it to not match spaces.

Upvotes: 3

Related Questions