Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. <?php
  2. //Format a string fo ruse with a HTML class or id attribute
  3. function str_class_id( $string, $strtolower = TRUE ){
  4.     $string = preg_replace( '/^([^a-z])/i', 'a$1', $string );
  5.     $string = preg_replace( '/[^a-z0-9-]/i', '-', $string );
  6.     $string = preg_replace( '/[-]+/', '-', $string );
  7.     $string = trim( $string, '-' );
  8.  
  9.     if( $strtolower ){ //Optionally lowercase the string
  10.         $string = strtolower( $string );
  11.     }
  12.  
  13.     return( $string );
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement