0

Possible Duplicate:
Function to return only alpha-numeric characters from string?

Starting from $string = "hey hello 9times-%&";

I would like to replace all the chars that are NOT numeric[0-9] or [a-z,A-Z] type.

Is there a good method to show this process control?

EDITED

i forgot that i need to leave blank space bar blank spaces, i mean:

"hey &/k" must return as "hey k" and NOT as "heyk"

2
  • replace them with nothing but leave all the original string's blank spaces Commented Sep 11, 2012 at 12:16
  • @GiantofaLannister sorry i must use remove NOT replace term Commented Sep 11, 2012 at 12:17

3 Answers 3

1
<?php

$string = "hey hello 9times-%&";
$string = preg_replace('/[^0-9A-Z\s]+/i', '', $string);

echo $string;

?>
Sign up to request clarification or add additional context in comments.

Comments

1
preg_replace('/[^ \w]+/i', '', $string);

That will work as well. See the codepad example.

Comments

1

What about preg_replace:

$clean = preg_replace('/[^0-9a-z\s]/i','',$input);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.