Posts Tagged ‘php’

Database Indexes on Domain Names

As part of a separate conversation Matt suggested something I had not given much thought to before. Say you have a database column that is used to store domain names. Something as simple as `domain` varchar(255) NOT NULL.
Of course you’ll want to search all of that data. Perhaps you want [...]

Read the rest of this entry »

PHP Helpers: make_slug

New function, make_slug -

if ( !function_exists( ‘make_slug’ ) ) {
function make_slug( $str ) {
$url_str = strtolower( trim( $str ) );

$url_str = preg_replace( ‘/[\s_]+/’, ‘-’, $url_str );
$url_str = [...]

Read the rest of this entry »

PHP Helpers: redirect_url

New function: redirect_url

if ( !function_exists( ‘redirect_url’ ) ) {
function redirect_url( $url, $status = 302 ) {
header( "Location: {$url}", TRUE, $status );
exit;
}
}

A special case wrapper around the header function to do URL [...]

Read the rest of this entry »

PHP Helpers: html_var_dump

With the last function being html_print_r this next one should come as no suprise, html_var_dump:

if ( !function_exists( ‘html_var_dump’ ) ) {
function html_var_dump( $data ) {
$out = "\n<pre class=’html-var-dump’";
$out .= " style=’border: 1px solid #ccc; padding: [...]

Read the rest of this entry »

PHP Helpers: html_print_r

Before I get to the next PHP Helpers function I wanted to mention that I’ve made the code available as a Google Code Project at http://code.google.com/p/php-helpers/. I added specific licensing terms ( MIT style ) – http://code.google.com/p/php-helpers/source/browse/trunk/license.txt. There’s also a changelog available to see when functions were added.
With that out of the way [...]

Read the rest of this entry »

PHP Helpers: esc_html

Next up in the PHP Helpers series is esc_html:

if ( !function_exists( ‘esc_html’ ) ) {
function esc_html( $html, $char_set = ‘UTF-8′ ) {
if ( empty( $html ) ) {
return ”;
[...]

Read the rest of this entry »

PHP Helpers: debug_log

I’ve been thinking recently about useful PHP functions, ones that are so handy that I’d like to have them available in every PHP code base I work on. These aren’t necessarily big elaborate functions, they do a single task and do it well. So I’ll be writing a series of posts called ‘PHP [...]

Read the rest of this entry »

PHP Count Performance

There was a question on the Utah PHP user group email list recently that went something like this: is calling count() on an array once and storing the result in a variable better/faster than calling count() multiple times?
I’d always thought that if you were going to need the count of an array more than [...]

Read the rest of this entry »

PDO Oddness

There are some parts of PDO that I find strange.
First up, why is the default fetch mode for the fetch function PDO::FETCH_BOTH? Returning twice as much data seems like a waste.
Second, but related to the first, why can’t you change the default fetch mode using PDO::setAttribute? It’s fine to be able [...]

Read the rest of this entry »

MakeItLink Update

With the upcoming release of WordPress 2.9 I thought this would be a good time to re-sync my original MakeItLink PHP class. I went back and did some additional checks with the make_clickable function in WordPress and found a few cases where it wasn’t generating the expected URL. That resulted in ticket #10990 [...]

Read the rest of this entry »