Are you handling all the possible conditions under which your programs will run?
For instance, do you always have a "default" case in you "switch" statements?
switch($some_value)
{
case 1:
$another_value = 1;
break;
case 2:
$another_value = 4;
break;
}
return(1 / $another_value);
What if $some_value is not 1 nor 2?
Notice: Undefined variable: another_value
Warning: Division by zero
What about "if" conditions? Do you have an "else" code section to all important "if" statements?
If your program is not expecting certain conditions but those conditions are not impossible to occur, having simple calls to error_log may help you to be aware of the problems under unexpected situations.
switch($some_value)
{
case 1:
$another_value = 1;
break;
case 2:
$another_value = 4;
break;
default:
error_log('unexpected some_value '.$some_value.' found ');
exit;
}
Contact Form
Followers
php best practices 1 - Handle unexpected conditions
php framework comparison - performance comparisons
I am writing this post regarding PHP framework performance comparisons. There are lots of PHP frameworks available and every framework has its own advantages and disadvantages. As all frameworks are based on MVC and thus adopting any of them for product development is not that difficult. Normally developers check for no of libraries load time and some important features like ORM. Also you can check that which framework supports which php version.
Here is a simple chart which programmers can use while choosing the suitable framework for their projects.
phpframeworks[.]com also have explained this thing in detail. You can check that also.
Jquery plugin to read query string - how to
If you are looking for some jQuery plugin to read the query string parameters then you are on right page. Here is a simple function which will help you to understand how to detect/read the values of query string parameters.
Jquery Plugin
$.queryParam = function(name){
var answer = new RegExp('[\\?&]' + name + '=([^]*)').exec(window.location.href);
if (!answer)
{
return 0;
}
return answer[1] || 0;
}
How to use
var paramValue = $.queryParam('paramName');
get X days back date from current date
How to get 7(X) days back date from current date?
PHP is very strong server side programming language which simplifies lots of small small tasks like converting date formats etc.I was working on some task, where I was suppose to get 7 days back date from current date. Actually the task is very simple, I am sharing the code here. Have a look at it and let me know if any one can find better way than this.
$format = 'YmdhIS'; // YOU CAN USE ANY FORMAT WHICH YOU WANT
$date = date ( $format );
// - 7 days from today
$prevDate = date ( $format, strtotime ( '-7 day' . $date ) );
Note: If you want to get yesterdays date then simply do -1 instead of -7.
How to get 7(X) months back month from current month?
// - 7 months from today$prevDate = date ( $format, strtotime ( '-7 month' . $date ) );
Its so simple.
Problems in enum data type mysql
I was wondering what could be the reason that most of geeks don't want to use this data type, I just googled out some info about it and came across some very serious issues, so sharing on my blog.
1. Changing the member list of ENUM columns is very expensive.
If your table has more than millions records and you are trying to change any thing in the column which has data type ENUM, then mysql rebuild complete table and look in to every row in that table. This may take lots of time may be hours and thus downtime. So lets create equation
Server Downtime = MySQL table with ENUM data type + millions of records. Lol.
2. ENUM has limited portability with other databases.
ENUM is not a standard SQL and lots of other databases doesn't have native support for ENUM.
Well there are lots of more issues with ENUM data type, I would like to share some links which may help you to take decision while using ENUM in your database. Check these links for sure , great information shared on it.
Link 1
Link 2
How to theme search results drupal 6.x
Lets take a scenario of having some text below each result in search result page, could be any kind of ad or some image or any HTMl component.
Step 1. Define a variable in a preprocess function in template.php file.
Step 2. Copy the search-result.tpl.php file from /modules/search directory to your current theme folder.
Step 3. echo the defined variable in the search-result.tpl.php file.
Step 4. Clear the template cache.
Step 1. Define a variable in a preprocess function in template.php file.
Append following code to template.php in current theme.
function mytheme_preprocess_search_result (&$vars) {
$vars['my_variable'] = t('I am here');
}
Step 2. This is self explanatory
Step 3. echo the defined variable in the search-result.tpl.php file.
Append following code at end of search-result.tpl.php
if (!empty($my_variable)) {
echo $my_variable
;
}
Step 4. Clear the template cache.
Now you can edit these files and can customize your search result page. :)
Do not register Youmint.com
If you are technical person then you can see that while registering the form data is sent via GET method and your personal data is passed to server without encryption. Password and all details are sent via GET method. I don't even Want to check what features they are providing after registration if this is the start.
► I am not the alone ◄ Check what other blogger are saying
sumans blog
replace last occurrence of substring from string in php
Are you looking out for a built in function in php which replace last occurrence of sub string from string??
You are at right place then. check out the function below which easily replaces the last occurrence of sub string from supplied string.
- function str_lreplace(mixed $search, mixed $replace, mixed $subject)
- {
- return substr_replace($subject, $replace, strrpos($subject, $search), strlen($search));
- }
Life becomes for Commuters in Pune
Google launched Transit service in Pune (in partnership with PMPML)
Public transport is a vital part of the infrastructure that makes our cities run efficiently, and can help mitigate congestion, environmental concerns, and increasing energy costs. Google earlier launched Transit in Banglore and delhi and now they come up with the idea in pune, making millions of commuters happy, as they can find out bus schedules and routes for 320 of PMPML buses via Google Maps on desktop and mobile.
As an example, here is the route from Pune University to MG Road.You can now check the bus no and available routes easily.
PMPML is the second Indian Bus service to launch on Google Maps.