Web Design Blog

PHP Scripts, Tips & Tricks

This is where we store some of our Web Development thoughts, tips and tricks, just because we like to share.

PHP- Alternative To The Depreciated mime_content_type Function And Fileinfo Functions

You’ve probably landed on this page because you want to find the Content-type of a file by using the mime_content_type function. But when you tried using the function, you were returned with a PHP error because it’s a depreciated function (PHP 4). Then you may have tried to use the Fileinfo function (am alternative suggested [...]

20 Dec 2011 / 0 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP- List All Directories/Folders From A Specified Location

This is a quick extension/counterpart to my existing blog post that explains how to List All Files In A Directory in PHP. But instead of listing all files, I’m quickly going to jot down how to list all directories/folders in a specified location. Someone had asked in the comments section how to do it, so [...]

20 Jul 2011 / 1 Comment / PHP Scripts, Tips & Tricks / by Maruf

PHP – Changing Date Format

A friend of mine has been struggling to format a date string he’s pulling out from a MySQL table. He’s just started learning PHP, so he’s still getting to grips with things. When he came to me with his problem, I sent him a link to the date function, but he couldn’t understand the manual’s [...]

09 Mar 2011 / 1 Comment / PHP Scripts, Tips & Tricks / by Maruf

PHP – Creating A Year (date) Loop

Here’s a good/efficient way of building a loop of years from a starting point to an ending point. For example, this code will show you how to print a range of years from 2000 to 2010: 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 The code is particularly useful if you want to [...]

30 Sep 2010 / 4 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP – Capitalize First Letter Of Every Sentence For Proper Formatting

Here’s an extremely useful snippet of code that will properly format sentences with capitalization. Actually, what the code really does is capitialize every letter AFTER a full-stop (period). Here’s an example of what the code will do… Before: Hello This Is An Example Of A Sentence Which Has Odd Capitalization Which You May Want Fixing. [...]

31 Jul 2010 / 5 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP – Populate Date Dropdowns – HTML Forms

Ok, i’m going to quickly jot down some PHP code, which dynamically populates date fields (dd/mm/yyyy) for HTML forms. I’m always using this code, but I never write it down, so i’m forever retyping it! To generate the date dropdown fields shown above, you could hardcode the values, like this…. 1 2 3 4 5 [...]

10 Jun 2010 / 1 Comment / PHP Scripts, Tips & Tricks / by Maruf

PHP- Using Preg_replace To Strip Date From URL

This is a very specific problem I was faced with a few days ago, so I doubt many people will find it directly useful. However, the solution to this problem can be used to resolve a load of tricky regular expression issues. The Scenerio A client recently changed permalink structures for his entire website. For [...]

18 Sep 2009 / 0 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP- Check If A Number Is Multiple Of Another Number

This is one of those posts that is purely a reminder for myself. It’s something so simple, but for some reason or another, I tend to forget. Suppose I have a loop, and I want to call a certain action on every 5th loop. For example, on the 5th, 10th, 15th..etc count, I want to [...]

13 Sep 2009 / 0 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP- Getting The Filename From A URL

Someone emailed me, asking me how to get the filename from a URL using PHP. It’s pretty easy, but I thought i’d jot it down for everyone, just in case other people want the same result. Example Ok, so we want the filename for the following page: http://www.anydomain.co.uk/page/grab.php We want to grab the filename, which [...]

27 Mar 2009 / 6 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP- Adding And Subtracting Dates

Here’s how you add and subtract dates from one another. For example, this simple code can calculate what the date will be 2 weeks before or after 1998-08-14 (yyyy-mm-dd). Subtracting days from a date The following example will subtract 3 days from 1998-08-14. The result will be 1998-08-11. 1 2 3 4 5 $date = [...]

06 Jan 2009 / 34 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP- Check If File Exists On Different Domain

Earlier today I needed to find out if a file exists on a different domain. Initially I used the file_exists function, but then when that threw back an error I remembered that file_exists only checks whether a file or directory exists on the same server as the script. After I played around with various functions, [...]

20 Nov 2008 / 11 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP- List All Files In A Directory

I’m working on a website for a client at the moment, and one of the features I need to do is display a bunch of images in a particular directory. It’s actually a very simple process in PHP and only requires a small amount of code. I’ve seen a lot of examples on other forums/websites [...]

02 Nov 2008 / 29 Comments / PHP Scripts, Tips & Tricks / by Maruf

2-Dimensional Arrays In PHP

I LOVE arrays. They make life so much easier and efficient. At first they can be quite difficult to get the hang of, but once you capture the basics, everything really does start to make sense. Each time I play with arrays I seem to learn something new. Here’s just a quick reminder to myself [...]

07 Oct 2008 / 0 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP- Count Files In A Directory

I’ve just added a new feature to the Team page, where i’ve added a small CSS image gallery. So now you can see multiple images of the awesome BrightCherryteam! I like everything to be automated so there is very little input from a human to make things work. To help make the thumbnail image gallery [...]

06 Sep 2008 / 22 Comments / PHP Scripts, Tips & Tricks / by Maruf

PHP: Remove Everything But Letters And Numbers – Reg Expressions

I always forget this PHP function, but I’m finding myself regularly needing it. I thought I’d just jot it down for my own reference and for anyone else who might need it. Function: ereg_replace What this function basically does is remove all characters from a string which isn’t a letter or a number. It can [...]

15 Jul 2008 / 10 Comments / PHP Scripts, Tips & Tricks / by Maruf
© 2012 BrightCherry :)