PDA

View Full Version : word wrap w/o URL


kenny873
05-16-2003, 04:39 AM
i would like to wrap a word which is great then 50 characters...therefore I use

$body = wordwrap($body, FORUM_WORD_WIDTH, ' ', 1);

but if the $body contains a very long URL, for example

http://www.averylongURL.averylongURLaverylongURLaverylongURLaverylongURLaverylongURLaverylongURLaverylongUR LaverylongURLaverylongURLaverylongURLaverylongURLaverylongURL.com.uk


and I don't want to chop/cut it..how can i do this?

missing-score
05-16-2003, 07:43 AM
Im not great with regex, so this will only be simple...


$url = "http://www.longurl.com/a/long/website/url/that/you/dont/want/chopped";

$url_str = preg_replace("/((http|https|ftp):\/\/.{15})(.*)(.{15})/i", "<a href=\"$1$2$3\">$1...$3</a>", $url);


I have tested it and it seems to work.