Categories
Database MySQL Web Development

The vagaries of NULL in MySQL

The concept of NULL in SQL, including MySQL, is a little hard to get at first, so the NULL keyword is tough to use as well.

This blog post helps to clarify it.

Categories
PHP

Extract the extension from a filename

This is a simple technique to extract the filename extension from a filename.  It could easily be adapted to extract the filename from a path or a query string from a URL by changing the first parameter of the explode() function.

$extension = end(explode('.', $filename));
Categories
DHTML JavaScript Web Development

Selecting All Text in a Form Field with a Single Click

Sometimes the text in a form field is put there primarily for the purpose of being copied to the clipboard.

In these cases a little JavaScript will smooth the process, selecting the full contents of the field on the first click.

Place the following script in the section of your page:

1
2
3
4
5
<script type="text/JavaScript">
function highlight(field) {
       field.focus();
       field.select();
}</script>

Then place onClick='highlight(this);' as an attribute to any field you want treated this way:

1
<input type="text" name="myfield" size="20" value="mytext" onClick='highlight(this);'>
Categories
Linux

Showing the path in the Linux command prompt

[sourcecode language="php"]
# show full path of current dir in linux command prompt
PS1="[\u@\h \w]\\$ "
[/sourcecode]

Categories
WordPress

Fixing the space between < and ?php in source code blocks

WordPress can have the disconcerting habit of inserting a space between the < and ?php when you want to show a code block in a syntax-highlighter plugin. To cure this, go into your WP Admin page, select the Settings menu, Select the writing submenu, then uncheck the WordPress should correct invalidly nested XHTML automatically option.