Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Format a string fo ruse with a HTML class or id attribute
- function str_class_id( $string, $strtolower = TRUE ){
- $string = preg_replace( '/^([^a-z])/i', 'a$1', $string );
- $string = preg_replace( '/[^a-z0-9-]/i', '-', $string );
- $string = preg_replace( '/[-]+/', '-', $string );
- $string = trim( $string, '-' );
- if( $strtolower ){ //Optionally lowercase the string
- $string = strtolower( $string );
- }
- return( $string );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement