Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 

Flaws of "and" and "or" operators in PHP

Today, When I was doing some programming stuffs and I found out that there is serious flaw in the and , or logical operator of PHP. Im not talking about the symbol || and && logical operator. Im talking about the and and or logical op...

Solution for error 'The requested address '/' was not found on this server' in cake PHP

If anyone face the error 'The requested address '/' was not found on this server' in cakePHP, then try these two steps:- Add function date_default_timezone_set() somewhere in you cake/app folder. If above solution not works then place date_...

Using Email or Username to login with auth in cakephp

We seldom need to login into application using Email or Username while using Auth with Cakephp. To achieve this we either need to write customized Auth component or we can achieve the same with the following code : public function validateUs...

Form submit in javascript

I would like to share an interesting feature that I found as I was trying to submit form through JavaScript. If you are trying to "form.submit()" through javascript and any form elements present with the name of "submit" in it, then in that case...

Time Difference between two timezones - Php

Many a times we need to take out time difference between two time zone using Date class in php. We can use the following code :- $timeZone = ['Any Timezone']; $default = date("Y-m-d h:i:s A");// UTC $dateTimeZone =...

How to download any CSV file while working with PHP

/* Header file to includes. fopen is use to open a file in write mode here. fputcsv function is use to output the CSV file having the name of columns and data coming from database. */ header('Content-Type: text/csv; charset=utf-8'); header('...

Date difference between two timezones in PHP

Here is a short function to get the difference between two timezones in PHP:- function diff(){ $date1 = "2014-02-27T20:00:00+04:00"; $date2 = "2014-02-28T07:20:00+08:00"; $diff = abs(strtotime($date2) - strtotime($date1));...

Get timezone from address or zipcode or address

Hi, We can get user's timezone if we have only address or zipcode of that user. First of all we need to get latitude and longitude then using these lat and long we can get timezone. However this is 2 step approach but it is much accurate becau...

How to create profile page hiding controller and action name in yii

How to create profile page hiding controller and action name in yii In url manager add this line '<username:\w+>'=>'site/index', username will be the parameter for name or id and site is controller name and the url will be...

Image Rotation by image magic

Creating image rotation using Image magic by command line. Some time image taken from iphone when uploaded on the website gets rotated .We can easily find that the image is rotated and can rotate is back by using the following code. $rot...

Bind Model in cakephp

In one of my project I have two table with simple relation Division (id, title) - hasMany Staff Staff (id, division&#95;id, name, jobtitle) So. Now I need to get some info like: I need to get all Staff where birthday today, and get r...

Get the title and meta tags from a url in php

To get the title and meta tags from a website you can use the following code : <html> <head> </head> <body> <?php function getTitle($Url){ $str = file&#95;get&#95;contents($Url); if(str...

Scrapping - get Select option values and text via simple html dom

Here is the working example to get select box option value and text via Simple html dom. I assume that you have already included simple_html_dom file and have html content in $content variable $html = new simple_html_dom(); // Creating htm...

What Is The Diffrence Between Do And Do While Loop

The Main Difference Between Do And Do While Loop Is :- Do while Loop :- If we use "Do While" at least one time execute the loop and then check the Condition. While Loop:- When we Use "While" then firstly check the condition after execute ...

Snapshot of any website from its URL

Get the snapshot of any website in php without writting a script <html> <head> <!--[if IE]> <style> #frame { zoom: 0.2; } </style> <![endif]--> </head> <body> <div class="test...

Getting the Code of any site using php script

Open the code view of any site : <?php $lines = file('http://www.whoznext.com/'); //Site url foreach ($lines as $line&#95;num => $line) { // iterate through each line echo "Line #{$line&#95;num} : " . htmlspecialchars($line...

How to inherit the properties and methods of base class to the child class in php

<?php class data<br> {<br> public $firstno;<br> public $secondno;<br> public function getData($fno,$sno)<br> {<br> $this->firstno=$fno;<br> $t...

Passing an array to the URL

Sometime you may need to pass the array in the url. You can do this as following: <?php $array["a"] = "A"; $array["b"] = "B"; $array["c"] = "C"; $array["d"] = "D"; $str = serialize($array); $strenc = urlencode($str); print $str ....

How to make UL/LI tree from a normal array

We usally wants to male a ul/li tree from an array having parent id within each individual record : $subjecttopic=Array ( [0] => Array ( [id] => 52b28146f484a5a410000029 [name] => Addtion ...

Using Ternary operator instead of If/Else in Php

Evaluating If Else statements is very common in programming paradigm. But 'If Else' statements are long and they can be easily replaced by simply using Ternary operators. Here is a tutorial on the usage of ternary operators and their implementati...

Extract method in PHP

Sometime we may need to use the same variable name that you are using in the query or simply in an associative array. Lets say you have an associative array : $arr = array( 'totalLimit' => 50, 'limit' => 10 ); The usually what we...

Using HeroDocs in php

Herodocs are useful for multi-line strings and avoiding quoting issues. It prevents from escapinging of characters in php EX1 ) $sql = <<<SQL select * from TABLE_NAME where id =1 and product_name = "widgets" SQL; O/...

How to create a class and object in php

class rect { public $length=0; public $width=0; public $area=0; public function getData() { $this->length=10; $this->width=20; } public function area() { $this->area = $this->leng...

Problem with foreach loop for updating array element

If we are traversing an array and need to update an element in some condition then it is quite tricky to do that in foreach loop. For example, if we need to increase each element by 2 of an integer array then we can do that using for loop in t...

Jquery vallidator rule for filling at least one field between a group

<script type="text/javascript"> $(document).ready(function() { jQuery.validator.addMethod("require_from_group", function (value, element, options) { var numberRequired = options[0]; var selector = options...

Parsing CSV file using php SplFileObject class.

The SplFileObject class provides an object oriented interface for a file. $file="upload_file.csv"; //file to parse Steps: 1) Create SplFileObject class object to the csv file. $srcFile = new SplFileObject($file); 2)Now loop ti...

Kohana issue on GoDaddy Shared Hosting

Recently while working for a project I faced an issue while making the site live. The site was developed with kohana framework and was to be hosted on Godaddy Server (Shared Hosting) and I faced a peculiar issue on the server giving me an erro...

Checking the date entered is according to a predefined format or not ?

Checking the date entered by the user correct of not as according to a predefined format or not. Example 1) $format = 'd-m-Y'; $input = 'asasasawasa-sldjs'; $date = DateTime::createFromFormat($format, $input); if($date) echo '...

How to create profile url in cakephp?

Hello readers ! Few days back I was facing issue to make public profile page in cakephp. And want to hide controller and action name from url for this I used the below code in routes.php and its work fine. Router::connect( '/:usernam...

Difference between array_slice() and array_splice()

**array_slice() Vs array_splice()** What arrayslice() function do: As name suggest this function just return part/slice of array which we pass to arrayslice() function as parameter 1 depending u...

Login either Username or Email using Authentication Plugin in Joomla

With the help of this Plugin user can login either with email or username . This plugin is compatible with Joomla 1.5, Joomla 2.5 and Joomla 3.1 . How to install Login to Joomla Administrator. Install with Joomla installer Proceed to y...

PHP array to JavaScript array conversion

Sometimes, I feel a need to get a PHP array in my JavaScript code. Earlier I make use of implode function of php but recently found new way using json_encode that works very effectively. Here is my php array: <?php $cool_epl_clubs_php =...

Sending xml data in post using curl

$xmldata =' <mail> <receive>you</receive> <sender>Surit</sender> <subject>Call me</subject> <message>XYZ</message> </mail> '; $url = "your url"; $curlConn = curl_init($url)...

Features for an e-Commerce Online Store

What is an e-Commerce? e-Commerce is doing business online and electronically. e-Commerce is about buying and selling products and services on the Internet. The sellers are individuals, small businesses or large corporations. The buyers are...

Using Auth method for login in cakephp

First of all load the component in the controller lets say UsersController using the below code $this->uses=array(Auth); login.view: <?php echo $this->Form->create('User', array('id'=>'signUpForm','name'=>'userSignu...

Date/Time Operations in php

Sometime there is a need to perform different operation on dates for ex: You may need to : 1) Add two dates/time 2) Subtract two dates/times for ex- to calculate your age by deducting your date of birth from current date. And many m...

Formatting time

Some time you may need to find the day, hour and min and seconds for ex: *you entered a number 105 and you want 1h-45Min ago* then you can simply use the following function although you can use your custom function as well depends on the...

Decomposing the associative array in chunks based on their keys

Consider you have two arrays like the below: 1) $arr1 = Array ( [0] => 2 [1] => 2 [2] => 2 [3] => 3 [4] => 3 ) 2) $arr2 = Array ( [0] => 28 [1] => 48 [2] => 21 [3] ...

iphone and Android Push Notification API

Push notifications are messages that allow an app to notify of a message similar to how a text message pops up on your screen with a sound. Code for Android ,Iphone API push notification is given below by using urbanairship. 1.Android Push No...
1 15 17 next
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: