Latest Articles

Use the navigation at the bottom to see older articles

How to read the contents of a file into a string in PHP

file_get_contents() can help us here. It reads a file and stores it in a string. Can be used with local files, as well as online content: $myLocalFile = file_get_contents(‘myfile.html’); $myOnlineFile = file_get_contents(‘http://wpguru.co.uk’); echo myOnline File; // would display the actual website This is different from the file() function which reads the contents of a file … Read more

How to replace text inside a string in PHP

If we have a string and would like to replace a portion of it, we can use the str_replace() function in PHP. It works like this: str_replace (‘whatToReplace’, ‘theReplacement’, ‘originalText’); It’s easy to remember… but I always get confused when I look this up in the manual. Here’s an example: $originalText = “Now is the … Read more

How to convert a timestamp into a readable date in PHP

A UNIX timestamp is something like a 10 digit (or less) integer number which represents the elapsed seconds since the 1st of January 1970 (also known as the Unix Epoch). It’s a very accurate representation of time, but not necessarily something us humans easily understand. A Unix Timestamp looks something like 1367805780. We can use … Read more

How to auto indent and collapse source code in Dreamweaver

I keep forgetting where and how to find this feature. Turns out the Command menu gives us such features: Commands – Apply Source Formatting (to Selection) Applies the correct indentations to the entire file, or your selection only. It’s the equivalent of Xcode’s “Editor – Structure – Re-Indent”. To manually move blocks of code, select … Read more

How to react to multiple UIAlertViews

If your class creates more than one UIAlertView, then you need a way to react to each of those accordingly. Problem is, you may only have one delegate that listens to all alerts at any given time. You could of course create a separate class for each alert view, but that’s a bit overkill. Instead, […]

How to add a WordPress user directly to the database

wordpress-iconSometimes you may want to add a new user to your WordPress site without accessing the admin interface. Here’s how we do that.

We need the following ingredients:

  • MySQL access details (host, username, password, database name – you can extract this from wp-config.php)
  • phpMyAdmin (or equivalent database management tool, such as Sequel Pro)

Let’s get started!

Read more