function make_clickable($ret) { $ret = " " . $ret; // in testing, using arrays here was found to be faster $ret = preg_replace_callback("#([s>])([w]+?://[w\x80-\xff#$%&~/.-;:=,?@[]+]*) #is", "_make_url_clickable_cb", $ret); $ret = preg_replace_callback("#([s>])((www|ftp).[w\x80-\xff#$%&~/.-;:=,?@[]+]*)#is", "_make_web_ftp_clickable_cb", $ret); $ret = preg_replace_callback("#([s>])([.0-9a-z_+-]+)@(([0-9a-z-]+.)+[0-9a-z]{2,})#i", "_make_email_clickable_cb", $ret);
// this one is not in an array because we need it to run last, for cleanup of accidental links within links $ret = preg_replace("#(]+?>|>))]+?>([^>]+?)#i", "$1$3", $ret); $ret = trim($ret); return $ret; }
当你在搭建网站时,很可能会从远程服务器上下载图片保存到你自己的服务器上,下面的代码就可以帮助你实现这个功能。 复制代码 代码如下: $image = file_get_contents("http://www.php100.com/image.jpg"); file_put_contents("/images/image.jpg", $image); //Where to save the image
当你使用Microsoft Word时,会创建很多标签tag,比如font、span、style、class等,这些标签在Word中十分有用,但当你从Word中把文本粘贴到网页上,就会出现很多没用的标签。下面实用的函数可以帮助你清除所有的Word HTML标签。 复制代码 代码如下: function cleanHTML($html) { /// /// Removes all FONT and SPAN tags, and all Class and Style attributes. /// Designed to get rid of non-standard Microsoft Word HTML tags. /// // start by completely removing all unwanted tags $html = ereg_replace("<(/)?(font|span|del|ins)[^>]*>","",$html); // then run another pass over the html (twice), removing unwanted attributes $html = ereg_replace("<([^>]*)(class|lang|style|size|face)=("[^"]*"|"[^"]*"|[^>]+)([^>]*)>","<1>",$html); $html = ereg_replace("<([^>]*)(class|lang|style|size|face)=("[^"]*"|"[^"]*"|[^>]+)([^>]*)>","<1>",$html); return $html }