Coder Profile - Show off your skills, get a coder profile.
 
 
 
  
Posted: 2.43 Years Ago 

VBAssassin
United Kingdom
Contrib Level: 17
Total Posts: 5,730
Hello Guys,

I've finished a prototype of this... but i will just post the implementation of how you use it. What do you think to this?
CODE: How to validate and clean multiple email address a... Copy / Restore  ::  Remove Scroll Bars
  1. print chain::create('!scott@site.com, me@site.com =,me@site.com, vbassassin@site.com')->
  2.        explode(',')->
  3.        trim()->
  4.        strtolower()->
  5.        filter('[a-z0-9.-]*@[a-z0-9.-]*')->
  6.        unique()->
  7.        implode(';')->
  8.        encode_mysql()
That code above does the following (line by line):

1. adds the string of email address... could also add this as an array, or even another chain object!
2. explode the string into an array based on the , character
3. trim leading and trailing whitespace from each element in the array
4. convert all the email addresses to lowercase
5. According to the regex, remove all characters that do not fit into the regex
6. make sure there are no duplicate email addresses in the array
7. now join up the array and glue the elements back together by adding a ; between each one
8. new escape the email address so they are safe to be inserted into a database.

the printed result is: "scott@site.com;me@site.com;vbassassin@site.com"

Another example
CODE: holding messages during form validation Copy / Restore  ::  Remove Scroll Bars
  1. $messages = chain::create();
  2.  
  3. //add a message
  4. $message[] = 'The name field must be filled in';
  5.  
  6. //add another messages
  7. $message[] = 'The address field must be filled in';
  8.  
  9. //can do this
  10. if (count($messages)) print "<p>" . $messages->trim()->ucwords()->implode('</p><p>') . "</p>";
  11.  
  12. //or this
  13. if ($messages->length()) print "<p>" . $messages->trim()->ucwords()->implode('</p><p>') . "</p>";
And another example
CODE: Hashing a secure password for storing in the datab... Copy / Restore  ::  Remove Scroll Bars
  1. chain::create($_POST['password'])
  2.        ->append('random characters to increase security')
  3.        ->append('seed such as their username')
  4.        ->md5();
Line by line:

1. add the users posted password
2. append some random characters to the password to make the hash stronger
3. append a unique seed such as the users username to the password to make the hash stronger still
4. md5 the string

And another example
CODE: Loading an external file and changing it Copy / Restore  ::  Remove Scroll Bars
  1. chain::load('usernames.txt')
  2.        ->explode("\ n")
  3.        ->trim()
  4.        ->unique()
  5.        ->escape_browser()
This will do the following:

1. Load the usernames.txt file
2. split up the usernames into an array, splitting each one by the line break
3. trim all whitespace from each name
4. remove duplicate names
5. escape the usernames so can be shown safely in the browser (prevents html, js, etc from being executed)

If you add ->save() to the end, it will overwrite the file, if you add ->('newfile.txt') it will save a copy of the new data in the newfile.txt file.

By the way, the class implements both the iteration interface (so the object can be used in foreach loops etc) and it implements the arrayaccess interface allowing direct access like an array eg: $a['key'] and unset($a[0]) etc. Also, you can extend the class to add your own unique chaining methods    Oh and the magic method __toString() is used to transparently convert the object to a string when required such as print $string;

Anyway, i'm going to run this as an open source project in a few weeks time... the website i will put up for it will be on my companies new web development platform (a website that creates websites). I will also dual license it under the GNU license and the MIT license.

Kind regards,
Scott
Page 1 of 1
 
 
Latest News About Coder Profile
Coder Profile Poll
Which sounds better on your coder profiles, and makes more sense to you (think twitter, facebook, etc)?

Followers / Following
Fans / Following
Fans / Fan Of


please login to cast your vote
and see the results of this poll
Latest Coder Profile Changes
Coder Profile was last updated
3.49 Years Ago
Official Blog :: Make A Donation :: Credits :: Contact Me
Terms & Conditions :: Privacy Policy :: Documents :: Wallpapers
Version 1.46.00
Copyright © 2007 - 2012, Scott Thompson, All Rights Reserved