Saturday 15 December 2012

Css fix for IE

CSS Specific for Internet Explorer

IE conditional comment is probably the most commonly used to fix the IE bugs for specific versions (IE6, IE7, IE8, IE9). Below are some sample code to target different versions of Internet Explorer:

<!--[if lt IE 8]> = IE7 or below

<!--[if IE 8]> = IE8

<!--[if gte IE 8]> = greater than or equal to IE8

<!--[if IE 9 ]> = IE9

<!--[if gt IE 9]> = greater than or equal to IE9


Here is the an example of including the styles for each version of IE

<!--[if lt IE 8]> 
<link href="ie7.css" rel="stylesheet" type="text/css" /> /* css for IE7 */
<![endif]-->

<!--[if gte IE 8]>
<link href="ie8.css" rel="stylesheet" type="text/css" /> /* css for IE8 & greater*/
<![endif]-->

<!--[if IE 9 ]>
<link href="ie9.css" rel="stylesheet" type="text/css" /> /* css for IE9 */
<![endif]-->

<!--[if gt IE 9]>
<link href="ie9.css" rel="stylesheet" type="text/css" /> /* css for IE9 & greater */
<![endif]-->


Hope this helps!

Friday 14 December 2012

Convert string to date in PHP


Sometimes it will need to convert the date in string format to convert it in to the original DATETIME format. In PHP we can do this like the following.

<?PHP
 
$date = "29/11/2012 23:26"; 
 
$newDate = preg_replace("/(\d+)\D+(\d+)\D+(\d+)/","$3-$2-$1",$date); 
 
echo date('Y-m-d H:i:s',strtotime($newDate)); 
 
?>

Hope this helps!

Tuesday 11 December 2012

Jquery HTML image rotator


Creating list of images that are rotating/sliding smoothly is not so much complex. You can achieve this in a few steps.

Here is an example. You can customize the style and script to make it suit for your applications. The present example will look like :



Hope you enjoy the script !

Check if an image is loaded or not in javascript

You can use javascript functions to check if an image is loaded. Here we are discussion two methods.

1) Using onload function

<script>
// Check using onload function 
 
objImg = new Image();
 
objImg.src = 'photo.gif';
 
objImg.onload = function() {   
 
// do some work   
 
}  
2) Using Complete property
<script>
// Check using complete  property 
 
objImg.src = 'photo.gif';
 
objImg = new Image();
 
 if(!objImg.complete) {  
 
// do some work   
 
} 
</script>

Hope this helps !

Monday 10 December 2012

Import csv file in PHP


Import data from csv/xls file is a main requirement in most of the web applications. We can do this simply by using the fgetcsv function in PHP. Here is the code for it.

<?PHP
 
// Import csv - PHP 
 
$row = 1;  
 
if (($handle = fopen("test.csv", "r")) !== FALSE) {  
 
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {  
     
        $num = count($data);
         
        echo "<p> $num fields in line $row: <br /></p>\n";
         
        $row++;
         
        for ($c=0; $c < $num; $c++) {
         
            echo $data[$c] . "<br />\n";
             
        }
         
    }
     
    fclose($handle);
     
}
 
?>
Its easy and so we can complete in a few steps.

Try it !


Jquery swf multiple image upload

Here is a plugin to upload multiple images simultaneously. It’s completely open source, so that you can download and customize to meet your requirements.

Upload


Browse Images



Save images


You can modify the upload-file.php in root folder to add the database connection/save code. Also the details regarding the file upload path also available with this file.


Try it, Its easy !




Friday 7 December 2012

Post XML data using CURL - PHP


A couple of methods are available to post an xml data to the server. Here we are showing how to post the xml data in HTTP post method by using CURL and PHP.

Here is the code.

<?PHP
 
// xml data 
 
$xml_data ='<RequestData> 
 
 <userID>'.uniqid().'</userID> 
 
 <lName>'.$lastname.'</lName> 
 
 <fName>'.$firstname.'</fName>
 
 <pass>'.$password.'</pass>
 
 <uGroupID>1</uGroupID>
 
 <rightID>1</rightID>
 
 <userNum>1</userNum>
 
 <emailID>'.$email.'</emailID>
 
 <isConsultant>1</isConsultant>
 
 <passChange>1</passChange>
 
 <passNoExchange>1</passNoExchange>
 
 <disabled>0</disabled>
 
 <saFailAttempt>1</saFailAttempt>
 
</RequestData>
 
';
 
// assigning url and posting with curl 
 
$URL = "http://172.16.0.44/RespackService/RespackService.svc/AddUser";
 
$ch = curl_init($URL);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
curl_setopt($ch, CURLOPT_POST, 1);
 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
 
curl_setopt($ch, CURLOPT_POSTFIELDS, "$xml_data");
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
$output = curl_exec($ch);
 
curl_close($ch);
 
// prints the output 
 
print_r($output);exit;
 

?>

Access asmx webservice from PHP using CURL


Consuming .asmx webservices is not so much complex nowadays.We can use CURL for posting variables to an asmx webservice. You can get the output in a few steps. Here are the details:

1)      Assign URL and variables
2)      Post using curl
3)      Prints the Output

Here is the code.

<?PHP
 
//web service URL and variables
 
$url = 'http://172.16.0.35/SoleTraderTaxiLocal/SoleTraderServices.asmx/SearchUsers'; 
 
$fields = array('AuthenKey'=>'172839',
    
'Criteria'=>'userfirstname',

'SearchText'=>'j',

'UserTypeiCode'=>'2',

); 
 
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } 
 
rtrim($fields_string,'&');
 
// Posting with CURL 
 
$ch = curl_init();
 
curl_setopt($ch,CURLOPT_URL,$url);
 
curl_setopt($ch,CURLOPT_POST,count($fields));
 
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 
$result = curl_exec($ch);
 
// Output to an xml file 
 
file_put_contents('content123.xml',$result);
 
curl_close($ch);
 
?>


Hope this helps!



Wednesday 5 December 2012

Get video details from youtube using PHP


This is a simple PHP class for fetching the complete video details from youtube.

The output is available as xml file and we can parse this to show in our application.


Try it for your applications.

If you have any queries, please send an email to support@innovativewebz.com




Force Download a file in PHP


PHP allows you to change the HTTP headers of files you're writing. This way you can force a file to be downloaded that normally the browser would load in the same window.  You can use this for files like PDFs, document files, images, or videos that you want your customers to download rather than read online.

<?PHP
 
// Force download in PHP 
 
$file="http://yourdomain/fileurl";  
 
header("Content-Description: File Transfer");   
 
header("Content-Type: application/octet-stream");   
 
header("Content-Disposition: attachment; filename=\"$file\""); 
 
readfile($file);
 
?>
There should be no spaces or carriage returns anywhere in the file. Blank lines will cause PHP to default to text/html and your file won't download.

Hope this helps !



Unset all cookies in PHP

Delete / Unset all cookies in PHP

If you want to delete all cookies on your domain, you may want to use the value of:
<?php   $_SERVER['HTTP_COOKIE']   ? >
rather than:
<?php  $_COOKIE  ? >
to dertermine the cookie names. 

If cookie names are in Array notation, eg: user[username] 

Then PHP will automatically create a corresponding array in $_COOKIE. Instead use  $_SERVER['HTTP_COOKIE']  as it mirrors the actual HTTP Request header. 

So you can unset all cookies by the following way.

<?PHP
 
// Unset all cookies in PHP 
 
if (isset($_SERVER['HTTP_COOKIE'])) {  
 
        $cookies = explode(';', $_SERVER['HTTP_COOKIE']);  
         
        foreach($cookies as $cookie) {  
         
                $parts = explode('=', $cookie);
                 
                $name = trim($parts[0]);
                 
                setcookie($name, '', time()-1000);
                 
                setcookie($name, '', time()-1000, '/');
         
        }
 
}
 
?>
Reference : http://php.net/manual/en/function.setcookie.php
Hope this helps!


Tuesday 4 December 2012

Jquery DatePicker - A simple datepicker plugin


It is a jquery plugin that attaches an inline calendar for selecting individual dates.

This will look like as below.

 

No complex coding or, integration required. Just include two files and jquery.

Then you can directly call the datepicker from your textfield id.


Check it and try for your applications.


Monday 3 December 2012

jScrollPane - A Jquery Scroll pane for web applications


jScrollPane 

jScrollPane is a cross-browser jQuery plugin by Kelvin Luck which converts a browser's default scrollbars (on elements with a relevant overflow property) into an HTML structure which can be easily skinned with CSS.

jScrollPane is designed to be flexible but very easy to use. After you have downloaded and included the relevant files in the head of your document all you need to to is call one javascript function to initialise the scrollpane. You can style the resultant scrollbars easily with CSS or choose from the existing themes. There are a number of different examples showcasing different features of jScrollPane and a number of ways for you to get support.

Here you can find the complete documentation and demos and downloads for the scroll pane implementation.


Check it and try this awesome jquery plugin for your web applications.