This lets you print PHP variable information, or any debugging code, to the screen, but only on your IP address. This is useful when you have to test on a live site, and for whatever reason you want to print to the screen rather than to error logs, but you don’t want visitors to see … Read more →
Archive for “PHP Code Snippets”
PHP code snippets and tips for customizing your own website, and for generating dynamic content with PHP.
Get a human-readable debug backtrace including the the file, the function which calls it, and its line number. Usage: The following will print it directly to your WordPress error log (/wp-content/debug.log).
This gets the visitor’s IP address, and hides the content from the IP address that you specify. This is for use on WordPress sites. One way to use it is in your single.php template file (or content-single.php). Replace this: … with this: Be sure to change the ‘126.96.36.199’ on line 21 above to the IP … Read more →
Here is a way of preparing a large amount of data to insert into a MySQL database table via PHP. This method works if your data is split up into multiple text files. If your data is already in a single text file, see Harvesting Data From A Text File instead. Note: My example is … Read more →
Here is a way of preparing a large amount of data to insert into a MySQL database table via PHP. This method works if your data is all in one text file. If your data is split up into multiple text files, see Harvesting Data From Multiple Text Files To Insert Into MySQL instead. Note: … Read more →
Updated to use prepared SQL statments and bound parameters. This lets you insert data from a PHP array variable into your MySQL database table. Before inserting, you must prepare your data into an array consisting of records that you want to insert into the database. This should be a two-dimensional array, in which each element … Read more →
This is for you if you are using the WordPress Comment Notifier Plugin by Satollo. The purpose of this is to automatically subscribe your existing commentators (which are people who have already made comments to your blog). You want to add these people as subscribers to this Comment Notifier Plugin, or they get left out … Read more →
This is a PHP function to get the current page URL with only PHP. This works within WordPress, as well. Example Usage One use for this is if you’re using ajax to process a form and return results to the page, and you’d like a link below the results to allow the user to “Return … Read more →
This is a PHP function to convert time from 24-hour format (HH:MM) into 12-hour format, with am or pm added. It takes two parameters: the hour the minute (with a leading zero for 0 through 9) It returns the time in 12-format like this: HH:MM am/pm
This will get the local time from the visitor’s browser. Then it converts PHP’s localtime() function into a readable display format, with leading zeros before the single-digit minutes. It also converts time into 12-hour format and appends the meridian ( am/pm ) to it. Then it displays the final time, formatted nicely, like See below … Read more →