Skip to content

Instantly share code, notes, and snippets.

@mytory
Last active October 19, 2021 13:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mytory/21d5c46bfaf0ee3640ff85a306d5ec42 to your computer and use it in GitHub Desktop.
Save mytory/21d5c46bfaf0ee3640ff85a306d5ec42 to your computer and use it in GitHub Desktop.
URL을 링크로 바꿔 주는데, 이미 링크가 걸린 a 태그는 건드리지 않는다.
<?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