How to Remove the Last Character of a String in PHP
October 28, 2022
If you need to remove the last character of a string in PHP, then you can do the following:
Read More
How to Create Function with Multiple Returns in PHP
October 27, 2022
If you need to create a PHP function that returns multiple values, then you can do one of the following.
Read More
How to Divide an Array into Chunks in PHP
May 20, 2021
If you have a single-dimensional array, and want to break it into chunks, you can use the array_chunks method.
Read More
How to Strip Script Tags in PHP
May 5, 2021
If you have some HTML input submitted from a user to your application, before saving it to the database, you may want to strip all <script> tags so that you can prevent cross site scripting attacks and other potential issues.
Read More
Recursively Delete Files and Folders and all Contents using PHP
June 10, 2020
Below is a quick and easy way to recursively delete all files and folders in a given path using PHP.
Read More
How to make a disk cache using PHP
April 5, 2020
If you have a busy PHP driven website and don’t want to make constant queries to the database for each user that will see the same data, then you can easily resolve this problem by letting the first of these visitors generate a cache for the consecutive visitors.
Read More
How to Follow Redirects with cURL for CLI or PHP
March 1, 2020
Let’s take a really common example. Say we want to follow redirects with cURL for google.
Read More
How to build a website quickly using PHP
February 1, 2020
PHP is a powerful scripting language created for the web.
Read More
Create daterange array of missing dates
February 20, 2014
<?php //fromDate 2014 - 01 - 22 //toDate 2014 - 02 - 20 //$arr Array( [0] = & gt; Array( [ISO_DATE] = & gt; 2014 - 02 - 18[DAY_SUM_AMOUNT] = & gt; 3000[DAY_SUM_VOLUME] = & gt; 2[CONVERSION_PCT] = & gt; 100 ) [1] = & gt; Array( [ISO_DATE] = & gt; 2014 - 02 - 19[DAY_SUM_AMOUNT] = & gt; 4000[DAY_SUM_VOLUME] = & gt; 1[CONVERSION_PCT] = & gt; 100 ) ) //codetime function createDateRangeArray($strDateFrom, $strDateTo) { $aryRange = array(); $iDateFrom = mktime(1, 0, 0, substr($strDateFrom, 5, 2) , substr($strDateFrom, 8, 2) , substr($strDateFrom, 0, 4)); $iDateTo = mktime(1, 0, 0, substr($strDateTo, 5, 2) , substr($strDateTo, 8, 2) , substr($strDateTo, 0, 4)); if ($iDateTo & gt; = $iDateFrom) { array_push($aryRange, date('Y-m-d', $iDateFrom)); // first entry while ($iDateFrom & lt; $iDateTo) { $iDateFrom += 86400; // add 24 hours array_push($aryRange,date('Y-m-d',$iDateFrom)); } } return $aryRange; } function recursive_array_search($needle,$haystack) { foreach($haystack as $key=>$value) { $current_key = $key; if ($needle === $value or (is_array($value) & amp; & amp; recursive_array_search($needle, $value) !
Read More
URL GET vars to PHP Array
May 14, 2013
Sometimes you will need to retrieve the GET variables passed into the current page URI or you will have a URL string to work from which contains certain GET variables, the below method helps a lot to convert them into an array which you can easily manipulate later.
Read More
Remove specific HTML tags using PHP
March 21, 2013
There are times when you want to remove a specific HTML tag from an HTML block of text.
Read More
Let Joomla and MySQL interact!
December 21, 2012
I often need a quick and easy few lines to retrieve some data from MySQL using Joomla without all the MVC nonsense that usually goes about this topic.
Read More
Refresh User Data in Joomla
October 21, 2012
I was busy with a custom component in Joomla, and it stored it’s own user_details based off of the main users table, but if the details were changed then I needed the system to update the session to reflect the changes.
Read More
Extract email addresses from a string – PHP
October 9, 2012
Sometimes you need to extract multiple email addresses from a string and the following function will make all your dreams come true.
Read More
Make a dynamic year dropdown using PHP
September 18, 2012
Ever wanted to have a dropdown that automatically showed the current year and the few years before it?
Read More
Pad a string with zeros using PHP
September 17, 2012
Recently I had to create a code/username maker to fit into a certain type of pattern so that all “broker codes” (as they were called) followed the same path.
Read More
Function split() is deprecated in PHP
June 12, 2012
You heard it right! split() is officially a deprecated function. That means that you can still use it if you are really brave and it will work correctly, but don’t expect to see it in later versions of PHP when they come out.
Read More
DateTime conversion function using PHP
May 1, 2012
It’s really very simple to convert times in different timezones using the following function.
Read More
Convert seconds to days, hours, minutes, seconds in PHP
May 1, 2012
With the following function you can easily convert an integer containing seconds to a nice days, hours, minutes, seconds string or array.
Read More
Get amount of hours between 2 hours
April 27, 2012
If you would like to get the amount of hours between 10:00 and 12:00 then use this!
Read More
How to get the Hours Difference (in HH:MM format) in PHP
April 12, 2012
It’s very simple to get the difference in hours using PHP
Read More
Warning: Invalid argument supplied for foreach()
February 28, 2012
A common error which occurs with foreach loops is the standard “Invalid argument supplied for foreach()” whch gets thrown up as a warning.
Read More
PHP nl2br on one line
February 18, 2012
I usually store data from a textarea directly to the database as is, then once I retrieve it back into HTML I use that lovely PHP function nl2br() to convert it to HTML
Read More
Remove all linebreaks in PHP
January 30, 2012
If you are having problems with a string that keeps adding a line break when output from PHP to HTML then the following code will work wonders for you!
Read More
Restrict PHPMyAdmin to IP Address
August 22, 2011
Would you like to restrict PHPMyAdmin from being accessible to the whole world?
Read More
WordPress wp-admin use different language for user
July 7, 2011
I needed to do some work on a WordPress site a little while ago and all the admins were French – and I cannot speak French other than the popular swear words – so had no idea what was going on in the /wp-admin/ so needed some way of enabling my newly created user account to be in english while letting everybody else use french as they had been up til that point.
Read More
Replace all spaces in HTML with except in HTML tags using PHP
May 29, 2011
If you would like to replace all the spaces in an HTML string with so that you can render it out to the browser but you also want to retain current spaces in HTML tags you can use the below method:
Read More
Using PHP to validate an IP address
May 18, 2011
You can use the PHP code below to check if an IP address is valid or not.
Read More
What is the difference between is_home() and is_front_page()
May 13, 2011
Call me ignorant, or call me an ignorant geek, but I used to think is_home() and is_front_page() was the same thing, until I experimented with them the other day and noticed they did quite different things.
Read More
Hide all error messages PHP
April 28, 2011
PHP Error messages showing up in your web applications are a dangerous thing.
Read More
What is xmlrpc.php?
February 22, 2011
It is a script which allows clients to make procedural calls over the net.
Read More
Stop That Referrer in PHP!
November 1, 2010
Today I will show you a method to stop the traffic that a referrer site is sending your way, you may wonder why you would want to ignore traffic, after all, isn’t inbound traffic to your site fantastic no matter what?
Read More
Ternary Operation
October 12, 2010
If you do not know what the Ternary operator is, or do not use it while you are coding, let me be the first to tell you how much you are missing out!
Read More
[Solved] PHP’s typeof – gettype()
September 6, 2010
Quite often you may need the ability to check what type of data type a variable is.
Read More
Actionscript 2 – PHP Data Transfer
May 17, 2010
In the below example we will use Actionscript 2 to call a remote PHP file that will return data to it.
Read More
Unique Random Numbers in PHP
May 13, 2010
If you would like to show random numbers using PHP you can do this:
Read More
HTML mail() Sending as Plain Text
May 11, 2010
$to = "[email protected]"; $subject = "SUBJECT"; $message = "<b>MESSAGE</b>"; $headers = 'MIME-Version: 1.
Read More
A PHP Mail Class
April 26, 2010
Below is a Mail class I created in PHP, it requires 4 arguments on initiation of the class via the constructor and uses the method ->send() to send the created mail once complete.
Read More
PHPExcel Class Usage
April 23, 2010
I just finished adding an export xls (excel) export feature to a web application.
Read More
phpMyAdmin – Invalid field count in csv input on line 1
April 9, 2010
I was trying to import a massive csv dataset into phpMyAdmin and it kept throwing error:
Read More
Get all directories in PHP
February 17, 2010
I think this may be the fastest way to get a list of all the directories in a given folder/directory using PHP.
Read More
What does __FILE__ in php mean?
January 26, 2010
In php there are a few magic constants and I find FILE to be a very useful one.
Read More
Get current working directory of php script/application
January 8, 2010
$myPath = realpath(dirname(__FILE__)); or $myPath = getcwd();
Read More
Force Download in PHP
December 16, 2009
This script works in all browsers, including Internet Explorer! 🙂
Read More
shortText function toggler in php
December 15, 2009
I often have to show a shortened version of a news item and then a link to show the entire news article or whatever.
Read More
PHP – file() lines
December 15, 2009
$lines = file('all-words.txt'); foreach ($lines as $line_num => $line) { echo "Line number ".
Read More
Send Email PHP Function
December 10, 2009
Ever find yourself typing the headers into the php mail() function over and over again?
Read More
PHP __autoload function
October 20, 2009
When PHP encounters a class that hasn’t been defined yet, you can use __autoload to automatically add them instead of including masses of included at the top of your files.
Read More
Sending data from javascript to php
October 20, 2009
If you ever find yourself needing to do some ajax and in turn sending strings of characters via javascript then you should really try encodeURIComponent() to wrap your strings in.
Read More
Uppercase the first character of each word in a string using PHP
October 20, 2009
You can use “ucwords()” to uppercase the first character of each word in a string.
Read More
Actionscript 3 equivalent of PHP’s print_r
October 20, 2009
A brilliant version of print_r for actionscript: http://dev.base86.com/solo/47/actionscript_3_equivalent_of_phps_printr.html
Read More