Last active
October 19, 2021 13:13
-
-
Save mytory/21d5c46bfaf0ee3640ff85a306d5ec42 to your computer and use it in GitHub Desktop.
URL을 링크로 바꿔 주는데, 이미 링크가 걸린 a 태그는 건드리지 않는다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* 아래는 참고한 자료. | |
* @link https://stackoverflow.com/questions/24651869/regex-matching-links-without-a-tag/24653720?stw=2#24653720 | |
*/ | |
function make_link_clickable($text) | |
{ | |
return preg_replace( | |
'!<a(.|\n)*?</a>(*SKIP)(*F)|' //skip a tag | |
. '(((f|ht)tp(s)?://)[-a-zA-Zа-яА-Я()0-9@:%_+.~#?&;/=]+)!i', | |
'<a href="$2">$2</a>', | |
$text | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment