code snippets in 140 characters or less
- Sharing:
-
String

Split string into an array of strings at pointer (3) (121)
Date Published: October 20, 2009
<?php
//split $str into an array of strings
at pointer (3)
$str = "Hello Friend";
$arr = str_split($str, 3);
print_r($arr);
?>

Convert a string into an array at pointer (,) (69)
Date Published: October 20, 2009
<?php
$str="foo,bar,baz,bat";
$arr=explode(",",$str);
print_r($arr);
?>

Convert an array into a string and create pointer (,) (110)
Date Published: October 20, 2009
<?php
$arr = array('lastname', 'email', 'phone');
$str = implode(",", $arr);
echo $str; // lastname,email,phone
?>

Convert a range into a string and create pointer ( | ) (106)
Date Published: October 20, 2009
<?php
$arr = range(1,10);
$str = implode(" | ", $arr);
echo $str; // 1 | 2 | 3 | 4 | 5
| 6 | 7 | 8 | 9 | 10
?>