implode(),explode()
Language/PHP 2010. 7. 2. 15:04
1. implode()
$array = array('lastname', 'email', 'phone');
$comma_separated = implode(",", $array);
echo $comma_separated; // lastname,email,phone
?>
2. explode()
<?php
// 예제 1
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode (" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
// 예제 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *
?>
// 예제 1
$pizza = "piece1 piece2 piece3 piece4 piece5 piece6";
$pieces = explode (" ", $pizza);
echo $pieces[0]; // piece1
echo $pieces[1]; // piece2
// 예제 2
$data = "foo:*:1023:1000::/home/foo:/bin/sh";
list($user, $pass, $uid, $gid, $gecos, $home, $shell) = explode(":", $data);
echo $user; // foo
echo $pass; // *
?>
'Language > PHP' 카테고리의 다른 글
headers already sent by 에러 (0) | 2010.07.05 |
---|---|
cookie (0) | 2010.07.05 |
Fatal error: Maximum execution time of 30 seconds (0) | 2010.07.02 |
php에서 javascript 사용, javascript에서 php 사용 (0) | 2010.06.23 |
브라우저 알아내기 (0) | 2010.06.23 |