Php:trim a string without cutting the word
function neat_trim($str, $n, $delim='...') { $len = strlen($str); if ($len > $n) { preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches); return rtrim($matches[1]) . $delim; } else { return $str; } }
function neat_trim($str, $n, $delim='...') { $len = strlen($str); if ($len > $n) { preg_match('/(.{' . $n . '}.*?)\b/', $str, $matches); return rtrim($matches[1]) . $delim; } else { return $str; } }
function formatUrl($sDispTitle){ $sDispTitle = str_replace('-','',$sDispTitle); $sDispTitle = str_replace(' ','-',$sDispTitle); $sDispTitle = str_replace(',','-',$sDispTitle); $sDispTitle = str_replace('&','',$sDispTitle); $sDispTitle = str_replace('/','-',$sDispTitle); $sDispTitle = str_replace('.','',$sDispTitle); $sDispTitle = str_replace('?','',$sDispTitle); $sDispTitle = str_replace("'",'',$sDispTitle); $sDispTitle = str_replace("!",'',$sDispTitle); $sDispTitle = str_replace('"','',$sDispTitle); $sDispTitle = str_replace('%','',$sDispTitle); $sDispTitle = str_replace('#','',$sDispTitle); return $sDispTitle; }
function isValidEmail($email){ return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email); }
$sTitle="test test123"; $sTitle = preg_replace("'\s+'", '-', $sTitle); print $sTitle; output:test-test123
function typevalidation($uploadfiletype,$mediatype,$tmpfilename="") { if ($tmpfilename) { $sfiletype = shell_exec("mimetype -bi $tmpfilename"); //echo "In".$sfiletype; $typearr=explode("/",$sfiletype); $filetype=$typearr[0]; $fileext=$typearr[1]; } if($uploadfiletype=='thumb') { if($filetype!='image') { $errmsg="errormessage1"; } else{ $errmsg="ok"; } } else if($uploadfiletype=='media') { if($mediatype=="image") { if($filetype!='image') { $errmsg="errormessage2"; } else {$errmsg="ok"; } } else if($mediatype=="video") { if($filetype!='video') { $errmsg="errormessage3"; } elseif(strpos($fileext,"flv")===false) { $errmsg="errormessage4"; } else {$errmsg="ok"; } } } return $errmsg; }
Want to know wants trending now on youtube just check
YouTube Trends Dashboard
A Google developed tool that hubs up all the great complimentary Google tools to understand the key target consumer, where and how they spend time. Essential for media planning!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <style type="text/css"> html { height: 100%; } body { height: 100%; margin: 0 auto; padding: 0px 250px; text-align:center; } </style> <title>Google Maps JavaScript API v3 Example</title> <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> <script type="text/javascript"> var geocoder; var map; var markersArray = []; var marker; var infowindow = new google.maps.InfoWindow(); var address = "153, Second Floor, Raghuleela Mall, Opposite Vashi Railway Station, Vashi Plaza, Vashi, Navi Mumbai,India"; function initializeMap() { geocoder = new google.maps.Geocoder(); var myOptions = { zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); codeAddressMap(); google.maps.event.addListener(map, 'click', function(event) { placeMarker(event.latLng); }); } function codeAddressMap() { geocoder.geocode({ 'address': address }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { clearOverlaysMap(); map.setCenter(results[0].geometry.location); marker = new google.maps.Marker({ map: map, title: results[0]['formatted_address'], position: results[0].geometry.location, animation: google.maps.Animation.DROP }); if(results[1] !=undefined) { infowindow.setContent(results[1].formatted_address); infowindow.open(map, marker); markersArray.push(marker); } } else { alert("Geocode was not successful for the following reason: " + status); } }); } function placeMarker(location) { geocoder.geocode({ 'latLng': location }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { if (results[1]) { clearOverlaysMap(); marker = new google.maps.Marker({ position: location, title: results[1].formatted_address, map: map, animation: google.maps.Animation.DROP }); infowindow.setContent(results[1].formatted_address); infowindow.open(map, marker); markersArray.push(marker); google.maps.event.addListener(marker, 'click', toggleBounceMap); map.setCenter(location); } } else { alert("Geocoder failed due to: " + status); } }); } function clearOverlaysMap() { if (markersArray) { for (i in markersArray) { markersArray[i].setMap(null); } } } function toggleBounceMap() { if (marker.getAnimation() != null) { marker.setAnimation(null); } else { marker.setAnimation(google.maps.Animation.BOUNCE); } } </script> </head> <body onload="initializeMap()" > <table width="800px" cellpadding="0" cellspacing="0" border="0"> <tr> <td colspan="2" align="center"> <h2>Map My Address</h2> </td> </tr> <tr> <td> <div id="map_canvas" style="height:300px; width:300px;" > </div> </td> </tr> </table> </body> </html>
Function removes unwanted utf-8 characters except correct ASCII & UTF-8 characters (excluding 4-byte+ UTF-8 sequences).
function removeInvalidUtf8Chars($s) { if(empty($s)) return $s; $s = preg_match_all("#[\x09\x0A\x0D\x20-\x7E]| [\xC2-\xDF][\x80-\xBF]| \xE0[\xA0-\xBF][\x80-\xBF]| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}| \xED[\x80-\x9F][\x80-\xBF]#x", $s, $m ); return implode("",$m[0]); return $s; }
Here is the Full source code for view counter application for counting the page views .
Please use the example.txt for how to use the application.
It uses memcache. Install the memcached daemon and php library to use it.
It uses mysql 5 and php 5.