wp_extract_urls( string $content )

Use RegEx to extract URLs from arbitrary content.


Parameters

$content

(string) (Required) Content to extract URLs from.


Return

(array) URLs found in passed string.


Source

File: wp-includes/functions.php

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 );
}


Changelog

Changelog
Version Description
WP-3.7.0 Introduced.