Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,197,736 members, 7,965,766 topics. Date: Thursday, 03 October 2024 at 08:39 PM |
Nairaland Forum / Science/Technology / Webmasters / Php User Defined Function Library (2623 Views)
I'm Getting "Warning: Session_start() [function.session-start]" Error. Pls Help / Need A Website Portal, Interactive Or User Defined Application / Writing A Time Based Expiration Script Or Function Using Php And Mysql (2) (3) (4)
Php User Defined Function Library by DualCore1: 4:38pm On Jul 29, 2011 |
The aim of this thread: post PHP functions you have created to make your coding experience better. Let's try to keep it at one function per post. Provide the function, an explanation of what problem it solves and an example usage. This should be fun, there's love in sharing . I'll go first ==================== I use this to generate a random ID of a specified length. The length you want is given in the argument. I cannot remember when I wrote this but I use it on every project I can remember. example usage $member_id = genId(15); //creates an alphanumeric string with 15 characters. ======================= function genId($length) { $characters = "0123456789abcdefghijklmnopqrstuvwxyz"; $string = ""; for ($v = 0; $v < $length; $v++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } ======================= |
Re: Php User Defined Function Library by Nobody: 6:10pm On Jul 29, 2011 |
Lets step it up a bit. Let us assume that you created ehm a website and then you specify that users should enter only an alphanumeric character as their usernames. How will you validate that? |
Re: Php User Defined Function Library by iwantto(m): 7:13pm On Jul 29, 2011 |
*dhtml: function isAlphaNumeric($var) { if(ctype_alnum($var){ return TRUE; }else{ return FALSE; } } |
Re: Php User Defined Function Library by Nobody: 7:37pm On Jul 29, 2011 |
function isAlphaNumeric($var) {return ctype_alnum($var);}Very good i_want_to |
Re: Php User Defined Function Library by iwantto(m): 7:47pm On Jul 29, 2011 |
*dhtml: function isAlphaNumeric($var) {return ctype_alnum($var);} Kai!!!!!!!! You too much. Nicely sempelized, U b sabi boy! |
Re: Php User Defined Function Library by Nobody: 8:06pm On Jul 29, 2011 |
Can also be written as: function isAlphaNumeric($var) {return ctype_alnum($var) ? true : false;} Or: function isAlphaNumeric($var) {return ctype_alnum($var)==true ? true : false;} Anyway, this is a good post. I must add that i never knew there was a direct function in php to solve this task - until you posted it @i_want_to - i normally use preg_match:
|
Re: Php User Defined Function Library by DualCore1: 8:40pm On Jul 29, 2011 |
Never came across that function. Thank you guys. Live use for this will be in enforcing higher password strength. Keep the functions coming devs. I will compile them and keep an updated copy on the first post for anyone to easily download. |
Re: Php User Defined Function Library by WeMaStEr(m): 9:11pm On Jul 29, 2011 |
atlast a reasonable thread. will post mine but i hope this una bot no go use me learn skills? |
Re: Php User Defined Function Library by TitoChhabr: 3:41pm On Sep 30, 2011 |
Hello Everyone, To keep the script from being executed when the page loads, you can put it into a function. A function will be executed by a call to the function. You may call a function from anywhere within a page, for more details please check out the following link, [url]http://mindstick.com/Articles/192928ef-1d2d-457e-9272-0fbae26af17a/?PHP%20User%20Defined%20Functions[/url] Thanks !!!!! |
Re: Php User Defined Function Library by sexyshe(f): 8:03pm On Oct 03, 2011 |
*dhtml: given how shortened you have made this wont it be cool to use the inbuilt function directly in the actual code? echo ctype_alnum($var)?"Thanks for submitting alphanumeric":"Please input alphanumeric"; |
Re: Php User Defined Function Library by dhtml1(m): 10:01pm On Oct 03, 2011 |
Of course, you can use it directly na. |
Re: Php User Defined Function Library by Mobinga: 5:04pm On Oct 04, 2011 |
A reasonable thread! Praise God. Ternary Operators can be confusing as hell. Ok this function generates a random alphanumeric password. function randP(){ $p = substr (md5 (uniqid (rand (),true)), 3, 10); return $p; } |
Re: Php User Defined Function Library by DualCore1: 5:44pm On Oct 04, 2011 |
Mobinga:Does the md5() fill a particular need? |
Re: Php User Defined Function Library by Mobinga: 8:27pm On Oct 05, 2011 |
Dual Core: Not at all. Just to more it more random. |
(1) (Reply)
Time To Stop Running After Adsense / Nairaland 504 Gateway Time-out Error / Online Banking Script And 101 Available Tools....
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 23 |