| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Moderator
Join Date: Jan 2005
Location: Brooklyn, NYC
Posts: 11,869
|
share your php functions
I thought this would be a good idea. Let's share our PHP functions! Handy bits of code that can improve our work. Here's some basic ones. A function for determining the "end of line". Just echo $eol wherever you want a line break in your HTML source. PHP Code:
Or a function for cleaning post input - stripping tabs, carriage returns, and new lines and such. It also adds escaping slashes if get_magic_quotes_gpc is false. PHP Code:
And the MySQLi database connection function I usually use is... PHP Code:
Find good advice in the beginners web design thread.
patrick o'neill web developer | blog | spam humor |
|
|
|
|
|
#3 (permalink) |
|
trouble free and loverlee
Join Date: Mar 2003
Location: YooKay
Posts: 2,854
|
Simple, but I found it useful when htmlspecialchars() and htmlentities() weren't doing the trick in an entirely utf-8, multi-lingual XML file: PHP Code:
Probably flawed, but worked for me when I needed it. |
|
|
|
#4 (permalink) | |
|
Moderator
Join Date: Jan 2005
Location: Brooklyn, NYC
Posts: 11,869
|
Quote:
Find good advice in the beginners web design thread.
patrick o'neill web developer | blog | spam humor |
|
|
|
|
#5 (permalink) |
|
I like code.
|
For when you need to convert colors from/to rbg/hex PHP Code:
|
|
|
|
#6 (permalink) |
|
Web Developer
|
Some usefull functions there Function to get the user IP, since one single technique doesn't always work PHP Code:
Or this one I got from another site, I don't remember where, it treats a string as if it is included by include(); Only downside is that you can't declare functions since it's already inside a function. PHP Code:
Or a function to echo a string and immediatly echo it without delay PHP Code:
This one transforms a filename into a clean string, to be used as a title or whatever (for example, go_go_gadget.exe becomes "Go go gadget" PHP Code:
|
|
|
|
#7 (permalink) |
|
Moderator
Join Date: Jan 2005
Location: Brooklyn, NYC
Posts: 11,869
|
Something new for you gents. Not a function, but a handy item in a function I'm working on. An array of (presumably) all the TLDs. PHP Code:
Find good advice in the beginners web design thread.
patrick o'neill web developer | blog | spam humor |
|
|
|
#8 (permalink) |
|
Web Developer
|
Here are a few I use a lot. Not mine, but found them on various websites. MySQL to PHP datetime converter: PHP Code:
Escape Data: PHP Code:
Validate E-Mail Address: PHP Code:
|
|
|
|
#9 (permalink) |
|
Moderator
Join Date: Jan 2005
Location: Brooklyn, NYC
Posts: 11,869
|
Similar to your datetime function, I wrote one today that takes a datetime ("YYYY-MM-DD HH:MM:SS") and breaks it up into its constituent parts and returns an array: PHP Code:
Find good advice in the beginners web design thread.
patrick o'neill web developer | blog | spam humor Last edited by pgo : 30-08-2007 at 17:38. |
|
|
|
#10 (permalink) |
|
Registered User
Join Date: Aug 2007
Location: Toronto, Canada
Posts: 16
|
I like functions that work like this in my class' PHP Code:
Or in my layout class: PHP Code:
And for testing $_POST, $_SESSION, $user, etc... PHP Code:
|
|
|
|
#11 (permalink) |
|
Registered User
Join Date: Aug 2007
Posts: 2
|
PHP Code:
|