1 2 3 4 5 |
function get_tweets($url) { $json_string = file_get_contents('http://urls.api.twitter.com/1/urls/count.json?url=' . $url); $json = json_decode($json_string, true); return intval( $json['count'] ); } |
Solid class to cleanup, filter and secure html / xml in your projects.
It is a small set of PHP scripts that will allow you to run your own URL shortening service. Have used it internally and for projects in the past.
“This is PHP implementation of QR Code 2-D barcode generator. It is pure-php LGPL-licensed implementation based on C libqrencode by Kentaro Fukuchi.”
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//path to directory to scan. $directory = "assets/images/thumbs/small/"; //get all image files with a .jpg extension. $images = glob("" . $directory . "*.jpg"); $imgs = ''; // create array foreach($images as $image){ $imgs[] = "$image"; } // sort by date if you like //usort($imgs, create_function('$a,$b', 'return filemtime($a) - filemtime($b);')); //sort by name //usort($imgs, create_function('$a,$b', 'return strcmp($b, $a);')); //display images foreach ($imgs as $img) { echo "<img src='$img' /> "; } |
Google adds PHP to its APP Engine. Time to take a closer look.
1 2 3 4 5 6 7 8 9 |
$tag = "p"; $html ="I am here!"; $dom = new domDocument('1.0', 'utf-8'); $dom->loadHTML($html); $dom->preserveWhiteSpace = false; $findTag = $dom->getElementsByTagName($tag); echo $findTag->item(0)->nodeValue; |
Anybody trying to use preg_replace on multidimensional arrays will see that the function is not working for those cases. Here a quick workaround:
1 2 3 4 5 6 7 8 |
function preg_replace_array($pattern, $replacement, $subject, $limit=-1) { if (is_array($subject)) { foreach ($subject as &$value) $value=preg_replace_array($pattern, $replacement, $value, $limit); return $subject; } else { return preg_replace($pattern, $replacement, $subject, $limit); } } |