Posts By:

PHP extract()

Posted by & filed under PHP.

You shouldn’t use this function on untrusted data, but if you clean it up – and know what the expected variables will be called – this is a handy function. Here an example $_POST: First clean the input: Now extract the key-value pairs into varname-values: There’s a pile of constants that control behaviour in case… Read more »

PHP mySQL Database backup

Posted by & filed under mySQL, PHP.

There are times when you need to get an SQL dump of a database but you don’t have access to management tools AND system(), exec() and passthru() commands are disabled. This script from David Walsh will do the trick:

Bash backup script

Posted by & filed under Linux, Server.

Here’s a script for backing up directories and databases. All files are compresses, and files older than 30 days are removed. # # Backup script # # Make compressed backups of directories/files, and old backups # Format: YEAR MONTH DAY – HOUR MINUTE SECOND DATE=$(date +%Y%m%d-%H%M%S) # backup directories and files tar -czf “/backup/target_file-$DATE.tar.gz” /home/username/public_html/home/… Read more »

Removing orphaned virtfs mounts

Posted by & filed under Linux.

Shows who is logged in: # who Anybody running a virtfs, or any orphaned virtfs users? cat /proc/mounts | grep virtfs Unmount them! for i in `cat /proc/mounts |grep virtfs |grep user_name_here |awk ‘{print$2}’`; do umount $i; done

Timthumb and Ajax

Posted by & filed under Ajax, Javascript, PHP.

Timthumb is a great tool for cropping/resizing images dynamically at the time the page loads. But what if you want to update the src of an image tag with a new image, for example, in an image carousel? You can use timthumb via an ajax call, but the resulting data is binary so you have… Read more »

Parsing XML: xpath attributes

Posted by & filed under PHP.

Here are two examples of getting attribute values using an xpath query: one using simpleXML and one using DOM document. Both queries are on namespaces within the XML file. First here’s the DOM Document version: … and the SimpleXML version:

.htaccess for canonical issues

Posted by & filed under Server.

Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTP_HOST} ^markflint\.net$ [NC] RewriteRule ^(.*)$$1 [R=301,L]

XML parsing and Namespaces

Posted by & filed under PHP.

Here’s a simpleXML script I used to parse a feed. There are MP3 links that are under the namespace xmlns:media=””. The links are in the feed like this: To get at the url attribute you first have to access the ‘media’ namespace by using children(‘media’,true). This tells the parser to find children of the namespace… Read more »