php tip

$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

This entry was posted in Career and tagged , . Bookmark the permalink.

2 Responses to php tip

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

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>