Categories
Php

Match a backslash with preg_match() in PHP

Sometimes you need to match a backslash with preg_match, but this is not as straightforward as you might first think! The preg_match() function is nothing but a perl-compatible regular expression pattern match. The preg_match() function searches a string for pattern and returning true while pattern exists, otherwise false. A backslash(“\”) is used to escape a […]

Categories
Php

Date range in PHP

Date and time values are very essential in PHP as there are different time formats, time zones, daylight saving offsets. By carefully with the date inputs you can format output however you like. In the below function you can get range of dates: function date_range( $start, $end, $step = ‘+1 day’, $format = ‘Y/m/d’ ) […]

Categories
Php

Permutation Of Multidimensional Array in PHP

Permutation of multidimensional array is a very interesting thing you can face somehow in your project once. Looping through is quite difficult rather than a function. Here we will show an example of permutation of a multidimensional array. Click Here to get the script. You will get the results as below: Array ( [0] => […]

Categories
Php

PHP Force Download

A force download script in PHP can give you more control over a file download rather than providing a direct link. Using a force-download script, you can: Validate whether a user is logged in Track total number of download <?php function force_download( $file, $new_name=”filename.doc” ) { $dir = “”; if ((isset($file))&&(file_exists($dir.$file))) { header(‘Content-type: application/force-download’); header(‘Content-Disposition: […]

Categories
Php

Word Cutter function in PHP

In WordPress, it is very popular to show excerpt of a content which shows up to particular word limits. In each and every cases it is not require to show the whole content rather than small content with limited words. Below function is an example of word limit or word cutter for a content. function […]

Categories
Php

PHP thumb creation and image merge

PHP thumb uses the GD library to create thumbnails from images (jpeg, gif, png etc) on run time. You can configure the output size and source will be entire image or a portion of original image. PHP uses imagejpeg function which output image to browser or file. Syntax: bool imagejpeg ( resource $image [, string […]

Categories
Php

PHP4 vs PHP5 | Difference between PHP4 and PHP5

PHP, Hypertext Preprocessor is a Open Source Language which is trend in the 20th century for creating and developing fast and dynamic web pages. This is also Server Side Scripting Language with a powerful tool for creating dynamic web pages. Lets see the difference between PHP version 4 and 5. Here is the difference between […]

Categories
Php WordPress

Block spam comments on WordPress using .htaccess

Using .htaccess you can block IP from where you are getting spam comments on WordPress in various form regularly and thus you can block spam comments. In this post, we wiil talk a little bit about what comment spam is and why it happens. we’ll show you easy ways to stop comment spam on your […]

Categories
Php

Display PDF in browser via PHP

Sometimes it is required to hide the actual PDF file name for security reason. So using a webpage you can display PDF in browser without knowing the actual URL. Example source: <?php $file = ‘path-to-pdf-file/myFile.pdf’; $filename = ‘download.pdf’; header(‘Content-type: application/pdf’); header(‘Content-Disposition: inline; filename=”‘ . $filename . ‘”‘); header(‘Content-Transfer-Encoding: binary’); header(‘Accept-Ranges: bytes’); @readfile($file); ?> Save this […]

Categories
Php

PHP date() and strtotime() return wrong months on 31st

On 31st of every month you will get a wrong month value while using date() or strtotime() functions. In that case you need to pass the date of the first day of the current month as a second parameter to the strtotime() function. For example: $base_month = strtotime(date(‘Y-m’,time()) . ‘-01 00:00:01’); echo date(‘Y-m’,strtotime(‘-1 months’, $base_month)); […]