Vijaya Kumar Blog

(Stunning PHP/MYSQL/AJAX/SEO Tips)

Entries for the ‘ PHP ’ Category

Use isset() Instead of strlen()

This is actually a neat trick. Here is the example: <?php if (isset($username[5])) { // The username is at least six characters long. } ?> When you treat strings as arrays, each character in the string is an element in the array. By determining whether a particular element exists, you can determine whether the string [...]

Leave a Comment

Shortcut the else in PHP

This tip accidentally stumbles upon a useful practice, which is to always initialize variables before you use them. Consider a conditional statement that determines whether a user is an administrator based on the username: <?php if (auth($username) == ‘admin’) { $admin = TRUE; } else { $admin = FALSE; } ?> This seems safe enough, [...]

Leave a Comment

Know the Difference Between Comparison Operators

This is a good tip, but it is missing a practical example that demonstrates when a non-strict comparison can cause problems. If you use strpos() to determine whether a substring exists within a string (it returns FALSE if the substring is not found), the results can be misleading: <?php $authors = ‘Vijay & Jana’; if (strpos($authors, ‘Vijay’)) [...]

Leave a Comment

Class to custom SQL DATETIME format using php

This class will be used to custom the SQL Datetime format in your style. This may very useful for web developers to make their work easy. Class (Store as “sql.date.class.php“): <?php class FormatDate { public function Date($SQLdate, $format) { $maketime = strtotime($SQLdate); return date($format,$maketime); } } $dateobj = new FormatDate; ?> Implementation (Store as “index.php“): [...]

Leave a Comment

MySql injection protection class in php

What is Mysql Injection? SQL injection refers to the act of someone inserting a MySQL statement to be run on your database without your knowledge. Injection usually occurs when you ask a user for input, like their name, and instead of a name they give you a MySQL statement that you will unknowingly run on [...]

Comments (4)

Alternate method for $_SERVER['SCRIPT_NAME'] to find exact filename

Now a days, all web developers/bloggers/SEO persons are using beautiful URL’s. Due to using beautiful URL’s, users can’t find, from which file name exact page is working. For Ex :- http://www.vijayakumar.org/profile/vijayakumar (It’s beautiful URL). But above mentioned URL will runs from file called profile.php [just guess]. How to find profile.php is a file? Is it [...]

Leave a Comment

Combine 2 MySql results using array on PHP

Main theme of this article is, searching values in 2 different MySql queries and combining both results as array using array_combine() and array_push(). Explanation is given under source code. <?php //connection parameters $username = “root”; $password = “”; $dbhost = “localhost”; $database = “test”; //Array creation $table1array = array(); $table2array = array(); $finalarray = array(); [...]

Comments (1)

Easy Multilingual (English & Tamil) Website creation using php

This article will help you to learn how multi lingual web sites can be done by your own. This is a try by testing with 2 languages (English & Tamil). This may useful for web developers for creating multi language web sites. Ok, let we start.., It’s very simple work, by fetching data from 2 [...]

Comments (30)

How to check online status for AIM, Yahoo!, MSN, Skype and ICQ users in PHP

You’re probably registered on at least one forum. And you’ve no doubt seen that in your forum profile, you can add your favourite Instant Messaging (IM) profile details, and other users can see if you’re online. You in turn, can see who else is online as well. Well what if you want to add that [...]

Comments (1)

Bulk “One Line” PHP scripts

Below scripts will be more useful for PHP developers to make their coding fast and efficiency. 1) Eliminate duplicate (or more) characters in a string (the underscore in the example below): $text = preg_replace(‘#(_)+#’,'_’,$text); 2) Randomly select of one element out of an array: $image = $image_array[array_rand($image_array)]; 3) Pass the htaccess/htpassword authenticated user to a [...]

Comments (4)

 

You need to log in to vote

The blog owner requires users to be logged in to be able to vote for this post.

Alternatively, if you do not have an account yet you can create one here.

Powered by Vote It Up