Category Archive: PHP
Posts about PHP
Found a couple of useful PHP code snippets for adding and removing query strings from URLs. This is useful when implementing paged and search functionality, among other things. These functions work great and are a real time saver — copy, paste, test, and done.
Here is a PHP snippet to truncate a string of text at the specified number of words. This is a nice alternative to just shortening a string of text based on character count. With this technique, the truncated string contains only complete words and is readable.
When you need to search an array using PHP, you can call upon the ancient powers of in_array() and call it a day. But that only works for flat, or one-dimensional arrays. What if you need to find a value in a multi-dimensional array? Well my friend, there isn’t a native PHP function to help […]
I recently had a conversation with an email guru concerning the ideal headers to use when sending plain-text email messages. Here is the punchline of that insightful exchange..
Some esoteric code phenomena for you today.. in this post I explain how PHP handles arrays when they are included in URL requests (via the query string). It’s something I failed to grasp until doing some in-depth work developing my professional WordPress firewall plugin. Now let’s jump in..
Here are three ways to list all files in a directory via PHP: via iterator class, file function, and while loop (in order of preference).
When working on a live site (which of course you should never do), it may be useful to execute some PHP script only for your own IP address. This quick tutorial provides a simple script that can make it happen. $referer = isset($_SERVER[‘HTTP_REFERER’]) ? _SERVER[‘HTTP_REFERER’] : ‘undefined’; $agent = isset($_SERVER[‘HTTP_USER_AGENT’]) ? $_SERVER[‘HTTP_USER_AGENT’] : ‘undefined’; $address […]
Including files plays an important role in PHP development. For example, your app may consist of a main plugin file that includes several smaller files, each of which contains some distinct bit of functionality. When including such files, it’s a good idea to protect them against direct access. This tutorial rounds up a bunch of […]
This code snippet takes a string of text and removes all carriage returns, new lines, and tabs, replacing any matches with a simple blank space. An ideal way to “stringify” a potentially formatted lump of alphanumeric text.
Here are some quick tips to help troubleshoot and fix image and file upload errors in WordPress. Hopefully it helps someone out there get things back on track with their uploaded images. I know it can be frustrating!
This post concludes our trilogy of posts on getting file and directory path information with PHP and WordPress. In this final path-related post, you’ll get numerous ways to get and include files from parent directories, subdirectories, adjacent directories, and even the same directory, just to round things out.
Massive round-up of PHP and WordPress techniques for getting various directory and file path information. This is a mega-reference aimed at PHP/WordPress developers.