Posts

Showing posts with the label php

How to add jQuery email validation in my site?

Image
I want to add jQuery email validation in my site which is good looking also simply copy and paste this code for add jQuery email validation for your site <script type="text/javascript" src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1.7.1"); </script> <script type="text/javascript">     $(document).ready(function(){         try {         var domains =['hotmail.co.uk','yahoo.co.uk','yahoo.com.tw','yahoo.com.au','yahoo.com.mx','gmail.com','hotmail.com','yahoo.com','aol.com','comcast.net','msn.com','seznam.cz','sbcglobal.net','live.com','bellsouth.net','hotmail.fr','verizon.net','mail.ru','btinternet.com','cox.net','yahoo.com.br','bigpond.com','att.net',

How to remove index.php from Codeigniter URL or .htaccess and codeigniter not working?

After  after visiting so many sites  article i solve this problem that why its not working with index.php or why sub page links are not working without index.php I think all article has same copy and paste code on their website that's why you are wondering here and there ... try this code i think this will definitely work for you if your site is uploaded on root of website than open you htaccess from you root and paste this code on you htaccess Options +FollowSymLinks All -Indexes Options All -Indexes DirectoryIndex index.php RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$0 [PT,L] if your site is inside in sub-folder of any site like www.site.com/yoursitefolder/ so you have to paste this code on your htaccess file of your codeigniter site Options +FollowSymLinks All -Indexes Options All -Indexes DirectoryIndex index.php RewriteEngine on RewriteBase /yoursitefolder Rewrit

How to add custom design twitter feed in php website?

If you are looking for twitter feed which you can customized your self then Simple copy and paste this code in your page for twitter feed and change the twitter username <?php     $username = "xyz"; // change the username     $limit = 5;     $feed = 'https://api.twitter.com/1/statuses/user_timeline.rss?screen_name='.$username.'&count='.$limit;     $tweets = file_get_contents($feed);   $tweets = str_replace("&", "&", $tweets); $tweets = str_replace("<", "<", $tweets); $tweets = str_replace(">", ">", $tweets); $tweet = explode("<item>", $tweets);     $tcount = count($tweet) - 1; for ($i = 1; $i <= $tcount; $i++) {     $endtweet = explode("</item>", $tweet[$i]);     $title = explode("<title>", $endtweet[0]);     $content = explode("</title>", $title[1]); $content[0] = str_replac

How to save an image with image validation in new folder in php?

If you want to save an image on a new folder which will create on run time and with image validation , then simply copy and paste this code and change the name of image field name and you can replace $id to your folder name. $id=$_POST['id']; $last_url = $_SERVER['HTTP_REFERER']; if(!empty($_FILES['uploadedfile']['name'])){ $imgExtension = array("jpg","jpe","jpeg","gif","png","GIF","JPG","JPEG"); $image_name = pathinfo($_FILES['uploadedfile']['name']); $extension = strtolower($image_name['extension']); if(in_array($extension,$imgExtension)){ $file_name = $_FILES['uploadedfile']['name']; $ext = end(explode('.',$file_name)); $folder_path = 'public/uploads/auction/'.$id; $save_path  = 'public/uploads/auction/'.$id.'/'.$file_name; $path  = 'publ

How to get alexa rank using php?

I tried to many script of alexa which return you the rank of website but they all script return 0 always. so i make a new alexa script which return exact rank of website and this works. simple copy and paste alexa script code in your php file, it will also work on localhost <?php     function alexaRank ($domain)     {         $remote_url = 'http://data.alexa.com/data?cli=10&dat=snbamz&url='.trim($domain);         $search_for = '<POPULARITY URL';         $part='';         if ($handle = @fopen($remote_url, "r")) {         while (!feof($handle)) {         $part .= fread($handle, 100);         $pos = strpos($part, $search_for);         if ($pos === false)         continue;         else         break;         }         $part .= fread($handle, 100);         fclose($handle);         }         $str = explode($search_for, $part);         $str = array_shift(explode('"/>', $str[1]));         $str = explo

How to add slide out div in our website?

How to add slide out div in our website? <style type="text/css" media="screen">     .slide-out-div {        padding: 20px;         width: 250px;         background: #f2f2f2;         border: #29216d 2px solid;     }     </style>     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" type="text/javascript"></script>            <script> /*     tabSlideOUt v1.3         By William Paoli: http://wpaoli.building58.com     To use you must have an image ready to go as your tab     Make sure to pass in at minimum the path to the image and its dimensions:         example:             $('.slide-out-div').tabSlideOut({                 tabHandle: '.handle',                         //class of the element that will be your tab -doesnt have to be an anchor                 pathToTabImage: 'images/contact_tab.gif',     //relative path to the image for the tab *

The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay

The SELECT would examine more than MAX_JOIN_SIZE rows; check your WHERE and use SET SQL_BIG_SELECTS=1 or SET SQL_MAX_JOIN_SIZE=# if the SELECT is okay if you have long mysql query or many joins and you got this error the use this  SET SQL_BIG_SELECTS = 1 example:  SELECT p.id as project_id,  p.job_number, p.time_to_complete , p.user_id, p.job_name, p.bid_date , p.bid_complete_date, p.service_id, p_docs.link, p_docs.username, p.status,  p_docs.password, p_docs.special_instructions, ord.amount, ord.payment_status, p.createDate , s.service_name , u.contact_name , u.f_number , f.name as franchise_name , v.name as vendor_name ,v.id as vendor_id , s.id as services_id , ord.order_date FROM wte_projects AS p INNER JOIN wte_projects_docs AS p_docs ON p.id = p_docs.project_id INNER JOIN wte_orders AS ord ON p.id = ord.project_id INNER JOIN wte_users AS u ON u.id = p.user_id  LEFT JOIN wte_franchise as f on f.code = u.f_number LEFT JOIN wte_services AS

How to add 301 redirecting in url add www before the url?

Url rewriting in htaccess 310 for redirecting the url from website.com to www.website.com and you can use this code to add 301 redirect to your webiste to redirect the url from without www to www like http://website.com to http://www.website.com simple copy and paste this code in your htaccess file and replace the website word to your website name RewriteCond %{HTTP_HOST} ^website\.com$ [NC] RewriteRule ^(.*)$ http://www.website.com/$1 [R=301,L]

How to create a CSV file from MySQL with PHP?

Create a CSV file from MySQL with PHP simple copy and paste this code to create the csv file from mysql with php and change the query according to your need. <?php mysql_connect('host','username','password'); mysql_select_db('database_name'); function remove_char($var) { $set = preg_replace('/[^a-zA-Z0-9-+@() \.\_\']/','padh',trim($var)); return $set; } function csv_create() { header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=".date('Y-m-d-h:i:s').".csv"); header("Pragma: no-cache"); header("Expires: 0"); $res = mysql_query("SELECT fname,lname,fullname,email FROM cs_users order by id"); echo "First Name,Last Name,Full Name,Email\n"; // fetch a row and write the column names out to the file while($val = mysql_fetch_array($res)) { $fname = remove_char($val['fname']); $lna

internal error or misconfiguration in codeigniter or php

 internal error or misconfiguration in codeigniter or php Internal Server Error  The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator , admin@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. so please Make sure your apache has mod_rewrite activated LoadModule rewrite_module modules/mod_rewrite.so If it is commented out (# in front), make sure to uncomment it and save the file. Checking if the corresponding module exists may be a good idea as well (but it usually does). IN simple language go on your running wamp or xampp click on that  and go on apche section and click on httpd.conf file and search mod_rewrite.so and remove the # in the front of line (# is use for comment)

How to generate random eight digit number in php?

To random generate the 8 digit code number Simple copy and paste this code in you php file and run the file You can also customize the code <?php                     $chars = "BC0DEFG1HJK3LMO4PQRS5TUW6XYZa7bcdefg8hijklimno9pqrst";                         $res = "";                         for ($i = 0; $i < 8; $i++) {  // you can replace 8 to any number to change the length of code                         $res .= $chars[mt_rand(0, strlen($chars)-1)];                         }                         echo $coupon_code = $res;   ?>

How to get time difference between two dates in specific format?

If are looking for a time difference in  specific format like : 2min ago, 2 hour ago, 2 week ago, 2 month ago You came right place simply copy and paste this code in you php file and run the file it will return you time , date format according to your need. <?php function getdiffrenceformat($time) {     date_default_timezone_set('Asia/Kolkata');     $mintime = getDifference(date("Y-m-d H:i:s"),$time,'1');     $hourtime = getDifference(date("Y-m-d H:i:s"),$time,'2');     $daystime = getDifference(date("Y-m-d H:i:s"),$time,'3');     $weektime = getDifference(date("Y-m-d H:i:s"),$time,'4');     $monthtime = getDifference(date("Y-m-d H:i:s"),$time,'5');     $yeartime = getDifference(date("Y-m-d H:i:s"),$time,'6');         if($mintime<=60)         {             return $mintime.' min ago';         }         elseif($hourtime<=24)         {  

How to separate url into a embed code of youtube?

how to separate url from a embed code of youtube ? there is a solution for Get url into a  embed code of youtube function getyoutubeVideolink ($code){     $a = array();     $b = array();     $c = array();     $a = explode('src',$code);     $b = explode('frameborder',$a[1]);     $b = explode('frameborder',$b[0]);     $c = explode('"',$b[0]);     return $c[1];     } $embed_code = '<iframe width="420" height="315" src="http://www.youtube.com/embed/GwQMnpUsj8I" frameborder="0" allowfullscreen></iframe>'; $url = getyoutubeVideolink( $embed_code ); echo $url; Now you can use this url in a iframe and where do you want

How to convert a string for url? or How to remove space or any special chrecter from my string?

How to convert a string for url? How to remove space or any special chrecter from my string? or How to convert a string in without space and without special character. use this code and you will got  a string for url or add with + sign <?php function filter_text($name){ $name = htmlentities(stripslashes($name), ENT_QUOTES); $name = preg_replace('/[^a-z A-Z 0-9]/','+',$name); $filtered = str_replace(' ', '+', strtolower($name)); return $filtered; } ?> if you got twoo or three + in a string so u can use two times these lines $filtered1 = str_replace('++', '+',$filtered); $filtered2 = str_replace('++', '+',$filtered1); like <?php function filter_text($name){ $name = htmlentities(stripslashes($name), ENT_QUOTES); $name = preg_replace('/[^a-z A-Z 0-9]/','+',$name); $filtered = str_replace(' ', '+', strtolower($name)); $filtered1 = str_replace('++'

How to get a date before or after 7 days from the current date using php programming?

getting a date before 7 days using php programming here is the code of to getting the date of 7 days before simply copy and paste this code on your page and and run this file on browser. <?php $m= date("m"); // Month value $de= date("d"); //today's date $y= date("Y"); // Year value echo date('Y-m-d', mktime(0,0,0,$m, ($de-7) ,$y)); ?> Note: You can change the diffrence  of date by changing the  " ($de-7)" 7 number to get  according yourself. you can also get a date after 7 days from the current date <?php $m= date("m"); // Month value $de= date("d"); //today's date $y= date("Y"); // Year value echo date('Y-m-d', mktime(0,0,0,$m, ($de+7) ,$y)); ?> Note: You can change the diffrence  of date by changing the  " ($de+7)" 7 number to get  according yourself.

How to change or rename all file name in a folder in php?

If you want change or rename All file name or all images name in a folder so you can use this code and manipulate this code according to your need. <?php if ($handle = opendir('foldername1/')) {     echo "Directory handle: $handle\n";     echo "Files:\n";     /* This is the correct way to loop over the directory. */     while (false !== ($file = readdir($handle))) {     echo $file;    $newnameArr=explode('.',$file);// make sure in your file name there should not be . (full stop in File Name )     $Change_imageName = "yourchangename".$newnameArr[1];        echo $Change_imageName.'<p></p>';     rename( "foldername1/$file","foldername2/$Change_imageName");     }     closedir($handle); } ?> Note=> Where "Foldername1" is that folder where is images place now And "Foldername2" is that folder where images will take place after rename or change the filename. F

How to read all file name in a folder in php?

Read all file name in folder or Directory Here is the script which will return you all file name from a folder or Directory <? if ($handle = opendir ('cartColor-60-75/')) {     echo "Directory handle: $handle\n";     echo "Files:\n";     /* This is the correct way to loop over the directory. */     while (false !== ($file = readdir ($handle))) {         echo "$file";         echo '<p></p>';     }     /* This is the WRONG way to loop over the directory. */     while ($file = readdir($handle)) {         echo "$file<br/>";     }     closedir($handle); } ?>

php interview question for 1-2 year experience

PHP-Mysql Interview Questions Q:1 How can we submit a form without a submit button? A:1 The main idea behind this is to use Java script submit() function in order to submit the form without explicitly clicking any submit button. You can attach the document.formname.submit() method to onclick, onchange events of different inputs and perform the form submission. you can even built a timer function where you can automatically submit the form after xx seconds once the loading is done (can be seen in online test sites). Q:2 In how many ways we can retrieve the data in the result set of MySQL using PHP? A:2 You can do it by 4 Ways 1. mysql_fetch_row. 2. mysql_fetch_array 3. mysql_fetch_object 4. mysql_fetch_assoc Q:3 What is the difference between mysql_fetch_object and mysql_fetch_array? A:3 mysql_fetch_object() is similar to mysql_fetch_array() , with one difference - an object is returned, instead of an array. Indirectly, that means that you can only

how to get the value of string between two word or charecter in string?

this function will return you the word or phrase in string which will come between two word or cherecter. function get_string_between($string, $start, $end) {     $string = " ".$string;     $ini = strpos($string,$start);     if ($ini == 0) return "";     $ini += strlen($start);     $len = strpos($string,$end,$ini) - $ini;     return substr($string,$ini,$len); } where $string is a string. $start is left word. $end is right word.

How to check if a string starts with a particular character in PHP?

You can use the substr  function in php and find the first character is exist in string or not if ( substr ( '_abcdef' , 0 , 1 ) === '_' ) { ... }