Archive | PHP RSS feed for this section

WordPress : Using Javascript libraries with your plugin or theme

21. June 2008

34 Comments

When you develop a WordPress plugin or theme, you might want to make use of some of the Javascript libraries distributed with the WordPress package such as Prototype, Scriptaculous and jQuery.

Continue reading...

PHP : Date difference in days

17. June 2008

30 Comments

You might need to calculate the date difference in days using PHP. You can easily calculate the days difference by using something like the code below.

Continue reading...

PHP : Array to Object

6. May 2008

33 Comments

I wrote a quick and simple function which allows you to quickly convert arrays to objects. It allows you to change an array like this :

Continue reading...

WordPress : get_pages

4. May 2008

3 Comments

The WordPress get_pages function works similar to the get_posts function which fetches posts from the database by criteria. The get_pages function takes different arguments and allows you to take control of parent and child pages as you execute the function.

Continue reading...

PHP : Strip filename from a URL

26. April 2008

11 Comments

Using PHP, you might need to strip the path from a URL, leaving behind just the filename at the end of the URL. You can achieve this with a regular expression pattern of course, but I have a much simpler solution. See the example code below.

Continue reading...

CakePHP : Form Radio Default Checked Value

17. April 2008

7 Comments

With the CakePHP FormHelper, you can output a set or a list of radio button widgets.

Continue reading...

CakePHP Crontab

28. February 2008

17 Comments

Due to the way that CakePHP rewrites URL requests with its router, it might seem confusing to execute a Crontab to run a controller action. I will show you how to set up a cron dispatcher so that you can execute all your different controller action schedules on a single file and pass the controller [...]

Continue reading...

PHP : Cannot use a scalar value as an array

26. February 2008

9 Comments

I was working on a WordPress plugin today and came across the most disturbing PHP warning error which I have never seen before in all the time that I’ve worked with PHP. The warning error message was : Warning: Cannot use a scalar value as an array What caused this error was when I tried [...]

Continue reading...

PHP: Random string with numbers and letters

1. October 2007

91 Comments

I thought that some of you might find it useful to learn how to generate a random string or a random number with PHP. I wrote a quick function to use PHP to generate random. See it below : function genRandomString() {     $length = 10;     $characters = ’0123456789abcdefghijklmnopqrstuvwxyz’;     $string [...]

Continue reading...

PHP : Strip or find a file extension

29. September 2007

4 Comments

Getting a file’s extension is essential when working with uploads and other manipulations complying with files. You might have a user uploading a file and you need to rename the file before moving it from the temporary upload directory. In order to do so, you can obtain the file extension and then rename it to [...]

Continue reading...