
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1060 Articles for PHP

435 Views
Example Live Demofunction sentence_split($text) { $before_regexes = array('/(?:(?:[\'\"„][\.!?…][\'\"”]\s)|(?:[^\.]\s[A-Z]\.\s)|(?:\b(?:St|Gen|Hon|Prof|Dr|Mr|Ms|Mrs|[JS]r|Col|Maj|Brig|Sgt|Capt|Cmnd|Sen|Rev|Rep|Revd) \.\s)|(?:\b(?:St|Gen|Hon|Prof|Dr|Mr|Ms|Mrs|[JS]r|Col|Maj|Brig|Sgt|Capt|Cmnd|Sen|Rev|Rep|Revd)\.\s[A-Z]\.\s)|(?:\bApr\.\s)|(?:\bAug\.\s)|(?:\bBros\. \s)|(?:\bCo\.\s)|(?:\bCorp\.\s)|(?:\bDec\.\s)|(?:\bDist\.\s)|(?:\bFeb\.\s)|(?:\bInc\.\s)|(?:\bJan\.\s)|(?:\bJul\.\s)|(?:\bJun\.\s)|(?:\bMar\.\s)|(? :\bNov\.\s)|(?:\bOct\.\s)|(?:\bPh\.?D\.\s)|(?:\bSept?\.\s)|(?:\b\p{Lu}\.\p{Lu}\.\s)|(?:\b\p{Lu}\.\s\p{Lu}\.\s)|(?:\bcf\.\s)|(?:\be\.g\.\s)|(?:\besp \.\s)|(?:\bet\b\s\bal\.\s)|(?:\bvs\.\s)|(?:\p{Ps}[!?]+\p{Pe} ))\Z/su', '/(?:(?:[\.\s]\p{L}{1, 2}\.\s))\Z/su', '/(?:(?:[\[\(]*\.\.\.[\]\)]* ))\Z/su', '/(?:(?:\b(?:pp|[Vv]iz|i\.?\s*e|[Vvol]|[Rr]col|maj|Lt|[Ff]ig|[Ff]igs|[Vv]iz|[Vv]ols|[Aa]pprox|[Ii]ncl|Pres|[Dd]ept|min|max|[Gg]ovt|lb|ft|c\.?\s *f|vs)\.\s))\Z/su', '/(?:(?:\b[Ee]tc\.\s))\Z/su', '/(?:(?:[\.!?…]+\p{Pe} )|(?:[\[\(]*…[\]\)]* ))\Z/su', '/(?:(?:\b\p{L}\.))\Z/su', '/(?:(?:\b\p{L}\.\s))\Z/su', '/(?:(?:\b[Ff]igs?\.\s)|(?:\b[nN]o\.\s))\Z/su', '/(?:(?:[\"”\']\s*))\Z/su', '/(?:(?:[\.!?…] [\x{00BB}\x{2019}\x{201D}\x{203A}\"\'\p{Pe}\x{0002}]*\s)|(?:\r?))\Z/su', '/(?:(?:[\.!?…] [\'\"\x{00BB}\x{2019}\x{201D}\x{203A}\p{Pe}\x{0002}]*))\Z/su', '/(?:(?:\s\p{L}[\.!?…]\s))\Z/su'); $after_regexes = array('/\A(?:)/su', '/\A(?:[\p{N}\p{Ll}])/su', '/\A(?:[^\p{Lu}])/su', '/\A(?:[^\p{Lu}]|I)/su', '/\A(?:[^p{Lu}])/su', '/\A(?:\p{Ll})/su', '/\A(?:\p{L}\.)/su', '/\A(?:\p{L}\.\s)/su', '/\A(?:\p{N})/su', '/\A(?:\s*\p{Ll})/su', '/\A(?:)/su', '/\A(?:\p{Lu}[^\p{Lu}])/su', '/\A(?:\p{Lu}\p{Ll})/su'); $is_sentence_boundary = array(false, false, false, false, false, false, ... Read More

12K+ Views
Large files can be uploaded using PHP in two ways. Both of them are discussed below −By changing the upload_max_filesize limit in the php.ini file.By implementing file chunk upload, that splits the upload into smaller pieces an assembling these pieces when the upload is completed.The php.ini file can be updated as shown below −upload_max_filesize = 50M post_max_size = 50M max_input_time = 300 max_execution_time = 300This should be avoided since it would change the settings of the server and other projects too.Updating the htacess filephp_value upload_max_filesize 50M php_value post_max_size 50M php_value max_input_time 300 php_value max_execution_time 300Changing the inline setting −ChunkingIn this ... Read More

945 Views
A value can be converted into a string with the help of (string) cast or the strval() function.The strval() function is a function call whereas (string) cast is an internal type casting method.Unless there is some specific dataset or use case, both of these can be used interchangeably.This is because PHP uses automatic type conversion, due to which a variable's type is determined based on the context in which it is used.The strval($var) function returns the string value of $var whereas the (string)$var explicitly converts the "type" of $var during the process of evaluation.The $var can be any scalar type ... Read More

640 Views
The functions and classes in PHP have global scope. This means they could be called outside a function even after they were defined inside the scope and the other way round.But PHP doesn't support function overloading, and it is not possible to redefine previously-declared functions.The function can be defined as an anonymous function and it can be unset after it completes its run.Below is a code sample for the same −if (function_exists('get_magic_quotes_gpc') && @get_magic_quotes_gpc()) $my_fn = create_function('&$v, $k', '$v = stripslashes($v);'); array_walk_recursive(array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST), $my_fn); unset($my_fn); }An anonymous function can't be called inside itself. The workaround ... Read More

4K+ Views
The fopen, fread and fwrite functions can be used to open a file stream, read a data stream and write that data to a file respectively.The file resource doesn't necessarily need to point to a location on the local machine itself.Below is an example that transfers a file from the local server to ftp server −$file = "file_name.jpg"; $destination = fopen("ftp://username:password@example.com/" . $file, "wb"); $source = file_get_contents($file); fwrite($destination, $source, strlen($source)); fclose($destination);The image needs to be transferred to an FTP server. Hence the server is opened in write mode, and the image is written to that location and the stream is ... Read More

293 Views
Constants in PHP are defined using the 'define' function. They are fairly slow in PHP.There are instances where extensions (such as hidef) were written to improve the performance of the code.This comes into picture when there are thousands of constants.Beginning from PHP version 5.3, compile-time constants with the help of const NAME = VALUE; can also be used. They are relatively quicker.

653 Views
Serialize is better in comparison to JSON to store PHP variables.The var_export can be used to save config file, and 'include' can be used to load the config file information.This is an easy way to save config data programmatically and easier to read/write. Below is a sample code for the same −config.phpreturn array( 'var_1'=> 'value_1', 'var_2'=> 'value_2', );test.php$config = include 'config.php'; $config['var_2']= 'value_3'; file_put_contents('config.php', '

571 Views
The reply and return path can be placed in the headers as shown below −$headers = 'From: sample@example.com' . "\r" . 'Reply-To: sample@example.com' . "\r" . 'Return-Path: sample@example.com'Otherwise, it can be passed as the fifth parameter to change the return path −mail($to, $subject, $message, $headers, "-f email@wherever.com");Here, 'email@wherever.com' has to be replaced with the user's respective email id.

304 Views
The below lines of code can be added to the /etc/phpmyadmin/config.inc.php file at the bottom −$i++; $cfg['Servers'][$i]['host'] = 'HostName:port'; // hostname and port are provided if they are not default values $cfg['Servers'][$i]['user'] = 'userName'; //user name for the remote server $cfg['Servers'][$i]['password'] = 'Password'; //the password $cfg['Servers'][$i]['auth_type'] = 'config';It will display “Current Server:” with drop down of both "127.0.0.1" and the one provided with $cfg['Servers'][$i]['host'].The user can switch between both the servers.

368 Views
PHP SOAP has been made available beginning from PHP version 5.0.1 . Users who are still using PHP4 need to use NuSOAP.Native PHP codes are better in terms of performance & relatively bug free. Hence it is suggested to use PHP SOAP if it is available.On the other hand, NuSOAP doesn't have much documentation on their official website as well.Salient features of NuSOAPIt comes with a few predefined methods whereas they need to be written on one's own in case of Soap.The performance metric for SOAP is server response time.Handling UTF-8 is much easier in Nusoap.Nusoap offers certain functions that ... Read More