10 января 2013 г.

RegExp

Удалить лишние пробелы из текста
$name= preg_replace("/\s{2,}/"," ",$name);

-------------------------------------------------

* Clean url as site URL
* Remove schema part and "www" part from the url
* Remove all path information. Keep only domain information.
* Exaple:
* input url: http://www.example.com/path?param#hash
* result: exaple.com
$trimedUrl = trim($url);
$cleaned = preg_replace('|^(?:\w+?://)?(?:www\.)?([^/]+)/?|i', '$1', $trimedUrl);

-------------------------------------------------