Create a slug from text

Remove whitespace and special chars and add dash.

Code:

    $url = 'How to access to private property in php5';
    $url = preg_replace("`\[.*\]`U","",$url);
    $url = preg_replace('`&(amp;)?#?[a-z0-9]+;`i','-',$url);
    $url = htmlentities($url, ENT_NOQUOTES, 'UTF-8');
    $url = preg_rep...

Date: 13/02/2012

Par: admin

0 comment

More info

Split text by new line

That would match line breaks on Windows, Mac and Linux!

 $array = preg_split ('/$\R?^/m', $string);

A line break is defined differently on different platforms, \r\n, \r or \n.

Using RegExp to split the string you can match all three with \R

Date: 08/02/2012

Par: admin

0 comment

More info

PHP5 inflector - underscored

Convert any "CamelCased" or "ordinary Word" into an "underscored_word"

Example:

 $word = 'MyClassPHP';
 echo  strtolower(preg_replace('/[^A-Z^a-z^0-9]+/','_', preg_replace('/([a-z\d])([A-Z])/','\1_\2', preg_replace('/([A-Z]+)([A-Z][a-z])/','\1_\2',$word))));

Results:

 my_class_php

Date: 04/01/2012

Par: admin

0 comment

More info

PHP5 inflector - camelize

Converts a word like "send_email" to "SendEmail". It will remove non aphanumeric character from the word, so "who's online" will be converted to "WhoSOnline"

Example:

 $word = 'send_email';
 echo str_replace(' ','',ucwords(preg_replace('/[^A-Z^a-z^0-9]+/',' ',$word)));

Result:

 SendEmail

Date: 04/01/2012

Par: admin

0 comment

More info