开发者

How to strip from a string those which are not in the a-z and 0-9 range?

开发者 https://www.devze.com 2023-03-20 14:26 出处:网络
I know a version of this but i\'m looking for the simplest开发者_开发百科 way? $string = \"HeLLo$ my222 name is zolee0802343134\";

I know a version of this but i'm looking for the simplest开发者_开发百科 way?

$string = "HeLLo$ my222 name is zolee0802343134";
$string = strtolower($string);
$replacement  = range (a, z);
$replacement2 = range (0, 9);

//
What comes here?
// 

I want to get this ->
$string = "hello my name is zolee";


Use regex for simplicity.

$string = "HeLLo$ my222 name is zolee0802343134";
echo preg_replace("/[^a-z ]/i", "", $string);

http://codepad.org/eDmXrnYR


Here you go: http://codepad.org/3KuCG2yf

<?php

$string = "HeLLo$ my222 name is zolee0802343134";
echo preg_replace("/[^a-zA-Z ]/", "", $string);

?>
0

精彩评论

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