WordPress at a glance

wp_extract_urls() WP 1.0

Use RegEx to extract URLs from arbitrary content.

✈ 1 time = 0.000114s = fast | 50000 times = 0.19s = very fast | PHP 7.0.8, WP 4.6.1

No Hooks.

Return

Array. URLs found in passed string.

Usage

wp_extract_urls( $content );
$content(string) (required)
Content to extract URLs from.

Changelog

Since 3.7.0 Introduced.

Code of wp extract urls: wp-includes/functions.php WP 5.2.4

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

Related Functions

From tag: Link (URL)

More from category: Helper Functions

No comments
    Hello, !     Log In . Register