Posts Categorized: PHP

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:

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:

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 »

Parsing WordPress wp-config.php file

Posted by & filed under OOP, Wordpress.

I need a script to extract the database details from the wp-config.php file so I could keep the logon details in one location when I was coding something outside the WP framework. I came up with a class that does this, connects to mysql and selects the database. There are three connection options: PDO, mySQLi… Read more »

WordPress XML-RPC publishing

Posted by & filed under Wordpress.

Well I thought I would try XML-RPC publishing in a WordPress blog. The main advantage I see in using RPC vs. email publishing is the use of font–styles. It also works with my SyntaxHighlighter plugin… I’m using the ScribeFire plugin for Firefox to write this blog, but Microsoft Live Writer looks like a good desktop… Read more »

Making a feed from Joomla Category

Posted by & filed under Joomla.

Use the following link and just change the category id: index.php?option=com_content&view=category&id=1&format=feed&type=rss See this link… there might be a better way in Joomla 1.5.22+ but this works fine. Link

WordPress permissions or ownership

Posted by & filed under Linux, Wordpress.

I was recently trying to upload a plugin to WordPress and found that the plugin could not create a directory. The problem was not directory permissions – it was user/group ownership. PHP running as fastCGI is running as user nobody on my VPS. I tried changing directory perms to 777 for wp-content/uploads and wp-content/plugins but… Read more »

Editing Joomla Modules

Posted by & filed under Joomla.

It’s useful to know that you can easily hack a Joomla module by opening the relevant module in the /modules directory. Edit the XML file for admin panel entries. Edit the mod_xxx.php file and the helper.php files for the PHP, or edit the file in the tmlp directory for the page HTML. Realy simple!