Posts

Showing posts with the label php

How to hide an email before @ in php?

If you are looking for a function in which you want a code to hide email before @ so just copy and paste this code. function hide_mail($email) {     $mail_part = explode("@", $email);     $mail_part[0] = str_repeat("*", strlen($mail_part[0]));     return implode("@", $mail_part); } Pass email id in it and this will hide the email before @ // *************@gmail.com

How to hide Phone number in PHP with different format?

How to hide phone number in PHP. I am using phone number in pp but i want a function in which i can add star in my phone number so can user can not read a phone number only some number will be visible and some number will be with asterisk. So i created a function in which i have added a code. You can just change the logic and change the format of phone number to hide the number. function stars($phone) { $times=strlen(trim(substr($phone,4,5))); $star =''; for ($i=0; $i <$times ; $i++) {  $star.='*'; } return $star; } // 99******54 above function will print a number like this

What is the difference between wamp lamp mamp xampp server?

Difference wamp lamp mamp xampp Server All thing is same in all Server which i have mentioned below This is a open source platform and you can free download and use it. Apache is the web server. Mysql is the relational database management system. PHP is the object-oriented scripting language. Wamp: Full form of WAMP is Windows, Apache, MySQL and PHP. WAMP Server is work on Windows Operating System only. Lamp : Full form of LAMP is Linux, Apache, MySQL and PHP. LAMP Server is work on Linux Operating System only LAMP is a combine package of Linux, Apache, MySQL and PHP. Mamp : Full form of MAMP is MAC, Apache, MySQL and PHP. MAMP Server is work on MAC Operating System only.   Xamp p: xampp stands for x-os, apache, mysql, php , perl. X-OS means it can be used for any operating system. XAMPP for major operating system including windows, mac, Linux. XAMPP Server come along with some additional features including support of perl, filezilla, m

How to use try and catch in Error Handling?

Try and catch in Error Handling It is possible for a script to use multiple exceptions to check for multiple conditions. It is possible to use several if..else blocks, a switch, or nest multiple exceptions. These exceptions can use different exception classes and return different error messages: <?php class myException extends Exception {   public function errorMessage() {     $errMsg= 'Error on line '.$this->getLine().' in '.$this->getFile()     .': <b>'.$this->getMessage().'</b> is not a valid EMail address';     return $errMsg;   } } $email = "sagar@domain...com"; try {   //check if   if(filter_var($email, FILTER_VALIDATE_EMAIL) === FALSE) {     //throw exception if email is not valid     throw new myException($email);   }   //check for "example" in mail address   if(strpos($email, "example") !== FALSE) {     throw new Exception("$email is an example e-mail");  

What is function Overloading and Overriding in PHP?

Overloading  :-  Function overloading means you want more work or login from a function or  you can use different login in a function. You can not use same function in a class so for use this login you can use __call magic function where you can pass method name and parameter and can add login according to their parameter. Take a look on code:- class test { public function __construct() { //Your logic for constructor } public function __call($method_name , $parameter) { if($method_name == "overlodedFunction")  //Function overloading logic for function name overlodedFunction { $count = count($parameter); switch($count) { case "1": //Business log in case of overlodedFunction function has 1 argument echo "You are passing 1 argument"; break; case "2": //Incase of 2 parameter echo "You are passing 2 parameter"; break; case "3": //Incase of 2 parameter echo "You a

How to remove blank array from an array?

How to remove blank array  from an array? like: you have an array where a key is blank and you want to remove the array from the tree of array then you can use this function like: function unsetblankarray($array)     {         foreach($array as $key=>$value)         {             if(!@$array[$key]['field'])             {                 unset($array[$key]);             }         }         return $array; }

Swap two variables value without using third variable in php?

We can swamp two variable with the use of php function  <?php $a='sagar'; $b='deepak'; list($a,$b) = array($b,$a); echo $a.'-'.$b; ?> deepak-sagar We can swap two variable with the use of XOR method too <?php $a='11111'; $b='22222'; $a = $a ^ $b; $b = $a ^ $b; $a = $a ^ $b; echo $a; echo $b; ?>   We can swap two variable with the use of our logic too <?php $a='11111'; $b='22222'; $a = $a + $b; $b = $a - $b; $a = $a - $b; ?> anther one is here   $a = $a * $b; $b = $a / $b; $a = $a / $b;

How to reverse a string without using php function in php?

How to reverse a string without using function in php <?php error_reporting(NULL); $string = 'This is a reversed string'; $len = 0; do{ $len++; } //$len is the length of string while($string[$len]!=''); for($i=$len-1;$i>=0;$i--){ echo $string[$i]; } ?> gnirts desrever a si sihT

What is difference between Array combine() and Array merge()?

Array_combine(): To Combines the elements of two arrays and Returns the New Array.The new Array keys are the values of First Array values and the new array values are Second array values. Array_combine()Example: <?php $arr=array(1,2,50); $arr1=array(452,672,542); print_r(array_combine($arr,$arr1)); ?> Output: Array ( [1] => 452 [2] => 672 [50] => 542 ) Array_merge(): merges two or more Arrays as New Array. Array_merge() Example: <?php $arr=array(101,301,501); $arr1=array(451,671,541); print_r(array_merge($arr,$arr1)); ?> output: Array ( [0] => 101 [1] => 301 [2] => 501 [3] => 451 [4] => 671 [5] => 541 )

How to make index.html default instead of index.php?

How to make index.html default instead of index.php?   Put a .htaccess file in your web root directory, if there isn't one yet. Then add the line: DirectoryIndex index.html index.htm index.php or change it accordingly. That line tells apache what file to look at first when it is not specified in the URL, in the same order that you put it after DirectoryIndex. In this example it would first look for index.html, load it if found, if not look for index.htm, load it if found, and if not load index.php. 

How to check that date is today and yesterday in php?

How to check that date is today and yesterday in php? Use this function for get today and yesterday function get_day_name ( $ time ) { $date = date('d/m/Y', $time);             if($date == date('d/m/Y')) {             $time_since = 'Today';             } else if($date == date('d/m/Y',now() - (24 * 60 * 60))) {             $time_since = 'Yesterday';             }else             {             $time_since = 'Today';             } return $time_since; }        

Force Redirect http:// to https:// in codeigniter by .htaccess

Force Redirect http:// to https:// in codeigniter by .htaccess simply copy and paste this code in htaccess of root  to redirect http:// to https:// # Enforce SSL https://www. RewriteCond %{HTTPS} !=on RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

How to create custom 404 redirect in codeigniter?

How to create custom 404 redirect in codeigniter? there are lots of post on website which told you about custom 404 redirect in codeigniter but most of them are worth less. Give a minute on this post and you will see this blog give exact what you want. Step first: Create a file in your controller errors.php and paste this code in this file <?php class Errors extends Controller { function Errors() { parent::Controller(); } function error_404() { $this->load->view('error_404'); } } ?> Step Two:  Create a file in your View folder name as error_404.php and write you error msg in this page Step Three: Now opne this file   yoursite/system/core/ Common.php and search this function  show_404() Please note: in many version common.php file in another folder so you can search for this file on this root also  yoursite/core/codeigniter/Common.php A nd replace this code with this function function show_404($page = '') { he

How to submit a form via curl in php?

How to submit a form by curl Lets take and example this is your submit form <form action="website.com/signup" method="post"> <input type="text" name="email" /> <input type="submit" name="submit" value="Submit" /> </form> and you want to submit this form by curl So, Simple copy and paste this in you php file and change field name and form action url and run the file This code will help you submit a form via curl <?php $fields_string =''; $url = 'website.com/signup'; $fields = array( 'EMAIL' => $_POST['email'] ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string, '&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL

How to upload a file in php with php validation of extension?

Simply copy and paste this code on your page And your input file name will be uploadedfile Like <input type="file" name="uploadedfile" /> and on submit of this page you will add this code $youruniqueid could be anything like userid or projected on the basis of this it will create folder for image upload $projId=$youruniqueid;    if(!empty($_FILES['uploadedfile']['name'])){     $imgExtension = array("jpg","jpe","jpeg","gif","png","GIF","JPG","JPEG","txt","pdf","PDF","docx","xlsx","pptx","pptm","doc","dot","xls","ppt");         $image_name = pathinfo($_FILES['uploadedfile']['name']);     $extension = strtolower($image_name['extension']);         if(in_array($extension,$imgExtension)){             $file_name = $_FILES['uplo

How to make a download link for download file in php

How to make a download link for download file in php or create a download link for download file in php? so here is the code and add base url according to your need   Create a php file download.php and paste this code in you php file $name = $_REQUEST['name']; // The file path where the file exists $filepath = 'http://www.site.com/files/'.$name; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); //setting content type of page header("Content-Type: application/force-download"); header("Content-Disposition: attachment; filename=".basename($filepath )); header("Content-Description: File Transfer"); //Read File it will start downloading @readfile($filepath); Now add this link in your file on your anchor tag like <a href=" http://www.site.com/download.php?name=file.png " >download link</a>

How to create thumb image of uploaded image in php?

Simply copy and paste this code in your page and call generate_thumbimage_thumbnail() somthing like that $path  = 'uploadediamgepath/myimage.png'; $save_path2  = 'project_image_thumb/thumb__myimage.png'; $iscopied2 = copy($path , $save_path2); if($iscopied2){ generate_image_thumbnail($path, $save_path2); } function generate_thumbimage_thumbnail($source_image_path, $thumbnail_image_path) { define('THUMBNAIL_IMAGE_MAX_WIDTH', 130); define('THUMBNAIL_IMAGE_MAX_HEIGHT', 130); list($source_image_width, $source_image_height, $source_image_type) = getimagesize($source_image_path); switch ($source_image_type) { case IMAGETYPE_GIF: $source_gd_image = imagecreatefromgif($source_image_path); break; case IMAGETYPE_JPEG: $source_gd_image = imagecreatefromjpeg($source_image_path); break; case IMAGETYPE_PNG: $source_gd_image = imagecreatefrompng($source_image_path); break; } if ($source_gd_imag

How to get second last array in php?

lets take an example like this is your array Array ( [0] => 14802 Stony Plain Rd NW [1] => Edmonton [2] => AB T5N 3S5 ) and you want to get second last array " Edmonton" then simple use this array like this end ( $array ); $z = prev ( $array ); this is effective and you can get second last array. :)

How to extract or fetch urls from text in PHP?

How to show url as a link from a text in php. this code will return you the link from a text . simply copy and paste this in you php file and call the function.  <?php             function make_clickable_string_url($text) {             return preg_replace_callback(             '#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#',             create_function(             '$matches',             'return "<br/><a href=\'{$matches[0]}\'>{$matches[0]}</a>";'             ),             $text             );             }         ?> it will return you the string as well as return a link of url which exist in content

How to create custom script to convert ttf, otf or font file to png image via image magic script?

Image
Please check that image magick must be install on your server please note  /usr/bin/convert this path could be change which is define below of script to find out the path of image magick make a new php page and paste this code on this page <?php echo "<pre>"; system("type convert"); echo "</pre>"; ?> and run the page and can check that path is right or not if path is changed so please change the path from  /usr/bin/convert this path Create custom script to convert ttf, otf or font file to png image via image magic script? this script will generate the image of ttf ,otf, .pfm , pfb or font file. simply copy and paste this code on your browser. <?php set_time_limit(0); ini_set('max_execution_time', 0); if($_SERVER['HTTP_HOST']=="localhost") { $DB["dbName"] = "fontxs"; $DB["host"] = "localhost"; $DB["user"] = "root";