PHPEdit.net Community
   
1 2 3 4
Tutorials Tips Pasties Code Snippets
 

Home > Code snippets

« < 1 - 2 > »

Code Snippets

Display code snippets from subcategory: PHP (12)

Various validation class

This is yet again a small class i wrote (still working on it) that validates some input data (not perfect tho, i know, but im still working on it).

File operations class (still under progress)

This is a small class i have been writing to perform several file operations. for now only list files on a single directory and the same but recursively. I will keep improving it and modifying this one here as I work on it.

Validate file extension (smaller code)

this is a file extension validation snipped i wrote some days ago, is smaller than the existing one here, and works really fine, it uses a small regex for the comparison and it does requires the . on the ext.

Nice error handleing for dev and live

A nice way to display errors when your on your dev area,
and then for the same errors to be sent to your email address when the site is on live, without having to change the code
all you have todo is, set your dev, live..defenitions
e.g. if (strstr($_SERVER['HTTP_HOST'], ".dev") {
define("DEV", true);
} else {
define("LIVE", true);
}
 
and then include the extension handler afterwards

Cookie Class

Cookie Class
very easy to use
 
set cookie: Cookie::set('car','abc 123');
get cookie: Cookie::get('car'); //return 'abc 123'
del cookie: Cookie::del('car'); //delete cookie car
del all cookies: Cookie::delAll();
isset cookie??: Cookie::exists('car'); //return bool value
empty cookie??: Cookie::isEmpty('car'); //return bool value

Removing Register Globals and Magic Quotes

If you are in the situation where you can not control is register globals are on or if magic quotes are on you need an easy way to remove them. Luckily with a single include file you can remove these items. Whether you are transitioning away from them or are on a host where you can not turn them off this will help you to ensure that the variables are cleaned out.

array_filter

Will filter out certain element of the array you don't want 

Remove Invalid XML Characters

When you are writing out an XML document there are certain characters that are not allowed in the document. If these characters exist, you will be unable to parse the document as per the XML specification.What this function will do is take a string, remove the invalid characters and then return the string back to you to insert into an XML document.

line_count

trying to work out the line count on extremly large text file can't be done by simple str_count for line breaks as you can't load the entire file into memory. this function hopfully helps with that.

Get first line

Truncate a given multi-line string by returning only a limited length substring from its first line. Add suspension points or other (provided) continuation mark if the string is truncated in-process; the input string is returned as-is if it does not contain new-line characters and its length is smaller than required.

Got one? Create it now.

View the most popular snippets.

Subscribe to comments Want to be up-to-date? Subscribe to snippets in your favorite feed reader.

 
PHPEdit User Community, © 2008 WaterProof SARL
Powered by PHPEdit