댓글 검색 목록

[php] 문서에서 URL찾아 링크 걸기

페이지 정보

작성자 운영자 작성일 15-05-07 19:01 조회 2,684 댓글 0

PHP :

 

<?php

 

// The Regular Expression filter

$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";

 

// The Text you want to filter for urls

$text = "The text you want to filter goes here. http://google.com";

 

// Check if there is a url in the text

if(preg_match($reg_exUrl, $text, $url)) {

 

       // make the urls hyper links

       echo preg_replace($reg_exUrl, "<a href="{$url[0]}">{$url[0]}</a> ", $text);

 

} else {

 

       // if no urls in the text just return the text

       echo $text;

 

}

?> 

댓글목록 0

등록된 댓글이 없습니다.

웹학교 로고

온라인 코딩학교

코리아뉴스 2001 - , All right reserved.