Welcome To Snipplr
Everyone's Recent PHP Snippets
- All /
- JavaScript /
- HTML /
- PHP /
- CSS /
- Ruby /
- Objective C
Sometime it is convenient to get recursive directory listing as array of items
directory => (file array)
Such as:
Array
(
[./a2temple] => Array
(
[0] => example13.zip
)...
2
654
posted 15 years ago by artoodetoo
If you want to set the active menu trail in a node, simply add this to your template.php in the 'template preprocess node' function.
0
608
posted 15 years ago by ccalnan
To make an image browser, add these lines:
$ext = strtolower(substr("$dirArray[$index]", strrpos("$dirArray[$index]", '.') + 1)); //get file extensions
if ("$ext" == "jpg") { // if file is a jpg
print("<TR><TD>$dirArray[$index]<br/><a href=\...
1
767
posted 15 years ago by beneberle
Shortens all strings in an array to a maximum length. Inserts '...' in between the first and last 6 letters
0
1069
posted 15 years ago by svenito
Given a start path will return an array of all subdirectories excluding files
0
1038
posted 15 years ago by svenito
Allows you to convert to any base between 2 and 255, effectively using all the ASCII characters.
In order to convert very large numbers with arbitrary precision you’ll need the BCMath lib. Without BCMath the large numbers will not be converted c...
1
829
posted 15 years ago by bucabay
This snippet allows you to update multiple rows of a database using a single form in one easy click
0
1335
posted 15 years ago by daveismyname
This snippet collects a date from a var and formats it into the correct format for database date entry
0
859
posted 15 years ago by daveismyname
There are plenty of classes out there to paginate through database results, well, here's one to paginate through a static array of items. Written quite a few years ago, recently recovered from a crashed drive.
1
539
posted 15 years ago by evilwalrus
2 login functions that check if a user is logged in by checking is a session is equal to true that would have been set on login.
If not logged in the redirect to login.php
1
825
posted 15 years ago by daveismyname
very useful function that allows you to redirect to the user to a given location
1
891
posted 15 years ago by daveismyname
Sometimes, the first or last block in a region needs to be styled different than the rest. This solution do this in simple way for Drupal 6.
(originaly code from [email protected]: http://drupal.org/node/293188#comment-1282186)
2
814
posted 15 years ago by Fake
Some valid UTF-8 characters are illegal in XML:
http://www.w3.org/TR/REC-xml/#charsets
This statement strips them from your strings.
0
2335
posted 15 years ago by jdbartlett
A simple function that generates a select drop down. It takes 3 values. The select name ,the mode (true for hours / false for minutes) and the selected option.
1
1120
posted 15 years ago by chchrist
Search Engine Optimisation, or SEO is something that a lot of bloggers get obsessed about, whilst others think it’s a load of rubbish. I’m halfway between the two – whilst I believe that you can change certain things to better SEO your content,...
0
652
posted 15 years ago by paulgrenwood
Whilst there are a number of ways of displaying thumbnails, this is still my favourite (even if it does require the most work!). First, upload timthumb to /wp-content/themes/yourtheme/ and create an image 250px by 250px with your site’s logo and up...
0
787
posted 15 years ago by paulgrenwood
This is something that I wished I’d thought of a long time ago – show other posts in the same series using not a plugin but custom fields. All you’ve got to do for this trick to work is create a custom field ‘Series’ with a link to each oth...
1
694
posted 15 years ago by paulgrenwood
E-mail validation is perhaps the most used validation in web forms, this code will validate email address and also optionally check the MX records of the domain provided in email address to make email validation more robust.
2
932
posted 15 years ago by paulgrenwood
This function will truncate strings only at word breaks which can be used to show a teaser for complete article without breaking words.
0
857
posted 15 years ago by paulgrenwood
Creating thumbnails of the images is required many a times, this code will be useful to know about the logic of thumbnail generation.
0
888
posted 15 years ago by paulgrenwood