php tip

Filed in Career 2 comments

$str = “home::khanhpt::test.tar.gz”;
$data = explode(“::”,$str);
$data[0] = “root”;
$name = join(“::”,$data);
echo $name;

You could use a regular express to remove everything apart from those characters you wish to keep:
$string=preg_replace('/[^A-Za-z0-9 _\-\+\&]/','',$string);

Replaces everything that is not (^) the letters A-Z or a-z, the numbers 0-9, space, underscore, hypen, plus and ampersand – with nothing (i.e. remove it).

cái này giờ mới biết, tiện ghê, há há, ghi lại kẻo quên, sau này có gì tìm lại cho dễ :D

hehe

Posted by thaiph   @   16 September 2009 2 comments
Tags : ,

Share This Post

RSS Digg Twitter StumbleUpon Delicious Technorati

2 Comments

Comments
Sep 23, 2009
10:06 am

explode phải sánh đôi với implode
split thì mới cặp bồ với join

Sep 27, 2009
4:31 pm
#2 Thaimeo :

thanks ku :x

Leave a Comment

Previous Post
«
Next Post
»
EXULT designed by ZENVERSE  |  In conjunction with Reseller Hosting from the #1 Web Hosting Provider - HostNexus.