If its necessary to extract all links from any text content - the next function will help in it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /** * Use RegEx to extract URLs from arbitrary content. * * @since 3.7.0 * * @param string $content Content to extract URLs from. * @return array URLs found in passed string. */ function wp_extract_urls($content) { preg_match_all( "#([\"']?)(" . "(?:([\w-]+:)?//?)" . "[^\s()<>]+" . "[.]" . "(?:" . "\([\w\d]+\)|" . "(?:" . "[^`!()\[\]{};:'\".,<>«»“”‘’\s]|" . "(?:[:]\d+)?/?" . ")+" . ")" . ")\\1#", $content, $post_links ); $post_links = array_unique(array_map('html_entity_decode', $post_links[2])); return array_values($post_links); } |
