Hello every one, welcome to my today's post on PHP. In my last post We learned about on How to send various kinds of email using PHP. Today I'm going to share 10 amazing and awesome PHP snippets , that will help you for building next web application in efficient manner. Though PHP has it's own rich library of functions but I'm trying to create my own functions and add them in my application.
Sometimes situation occurs and on that time we need to modify built-in functions according to our work requirements. I'd also faced a lot of difficult situation while developing software's. From my modified code gallery, I love to share some of codes with you. They really worked and working so far for my self very well. I think they not only reduce your valuable times but also save your energy in software development session :) So, Lets start....
function get_tomorrow_date() {
$tomorrow = mktime(0,0,0,date("m"),date("d")+1,date("Y"));
return date("Y-m-d", $tomorrow);
}
function get_today_date() {
$today=date("Y-m-d");
return today;
}
function get_last_date() {
$tomorrow = mktime(0,0,0,date("m"),date("d")-1,date("Y"));
return date("Y-m-d", $tomorrow);
}
function is_localhost() {
$localhost_ids = array('localhost', '127.0.0.1');
if(in_array($_SERVER['HTTP_HOST'],$localhost_ids)){
// not valid
return 1;
}
}
function get_day_name_by_date($day,$month, $year) {
$day_name = date("l", mktime(0,0,0,$month,$day,$year));
return $day_name;
}
function debugPrint($object, $title = "", $isMarkup = false) {
if( !empty($title)){
echo "$title: ";
}
if( $isMarkup == false){
echo ""; print_r($object); echo "
";
}
else{
echo htmlspecialchars($object);
}
}
function Month($NumMonth) {
switch($NumMonth) {
Case "01":
return "January";
break;
Case "02":
return "February";
break;
Case "03":
return "March";
break;
Case "04":
return "April";
break;
Case "05":
return "May";
break;
Case "06":
return "June";
break;
Case "07":
return "July";
break;
Case "08":
return "August";
break;
Case "09":
return "September";
break;
Case "10":
return "October";
break;
Case "11":
return "November";
break;
Case "12":
return "December";
break;
}
}
function setDescriptionString($inputString=""){
$replacedWords = array("…","‘","ó","","
", "/",":", "<", ">","", "", "", "", "","","span","strong","class","+","-","=","'","’"); $filteredString = str_replace($replacedWords, "", $inputString)."."; return $filteredString; }function getExtension($str) {
$i = strrpos($str,".");
if (!$i) {
return "";
}
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
function removeSpacialCharacters($string="") {
if (preg_match('/[^\w\d_ -]/si', $string)) {
return preg_replace('/[^a-zA-Z0-9_ -]/s', '', $string);
} else {
return preg_replace('/\s/', ' ', $string);
}
}
Was this information useful? What other tips would you like to read about in the future? Share your comments, feedback and experiences with us by commenting below!
You might also like...
Md Mahbub Alam Khan is the Editor and Founder of CoolAJAX Web Blog. You can follow CoolAJAX on Twitter , on Facebook or you can subscribe via RSS .
Topics