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ễ 😀


2 thoughts on “php tip”

Leave a Reply