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

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);
?>
››Link
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);
?>
››Link
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
?>
››Link
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
?>
››Link
Check if value is in array and returns Yes or No (126)
Date Published: October 20, 2009
<?php
$names = array( 'Bob', 'Jim', 'Mark' );
echo 'In Array?';
if (in_array(foo, $names))
echo 'Yes';
else
echo 'No';
?>
››Link
Regex check if zipcode is in range and return Yes or No (123)
Date Published: October 20, 2009
<?php
$zipcode='09607';
echo 'Zipcode in range?';
if(preg_match('/^096[0-9]{2}$/'
, $zipcode))
echo "Yes";
else
echo "No";
?>
››Link
Automatic Copyright Year [CSS-TRICKS.COM](35)
Date Published: October 20, 2009
<?php echo "© " .
date("Y") ?>
››Link
Change Month Number to Month Name [CSS-TRICKS.COM](92)
Date Published: October 20, 2009
<?php
$monthNum = 9;
$monthName = date("M", mktime(0, 0, 0,
$monthNum, 10));
echo $monthName;
?>
››Link
Find File Extension [CSS-TRICKS.COM](94)
Date Published: October 20, 2009
<?php
$filename = 'mypic.gif';
$ext = pathinfo($filename,
PATHINFO_EXTENSION);
echo "." . $ext;
?>
››Link