Howto create an empty object in PHP
To create an empty object use stdClass
$obj = new \stdClass();
To create an empty object use stdClass
$obj = new \stdClass();
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...
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
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
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