Posted By

aludwig on 06/09/11


Tagged

String


Versions (?)

simpleStringMaker


 / Published in: PHP
 

The PHP version of simpleStringMaker has an argument to replace spaces with hyphens.

  1. function simplestringmaker ( $thestring, $hyphens ) {
  2. $newstring = '';
  3. for ( $i = 0; $i < strlen( $thestring ); $i++ ) {
  4. $c = ord(substr($thestring, $i, 1));
  5. if ( ($c > 47 && $c < 58) ||
  6. ($c > 96 && $c < 123) ||
  7. ($c > 64 && $c < 91) ) {
  8. $newstring .= strtolower( chr($c) );
  9. } else if ( $c == 32 && $hyphens ) {
  10. $newstring .= '-';
  11. }
  12. }
  13. echo $newstring;
  14. }
  15.  
  16. simplestringmaker ( "It's 419: Gotta Minute..?!", 0 );

Report this snippet  

You need to login to post a comment.