wpseek.com
Outil de recherche WordPress pour les développeurs et auteurs de thèmes



wp_extract_urls › WordPress Function

Depuis3.7.0
Dépréciéen/a
wp_extract_urls ( $content )
Paramètres:
  • (string) $content Content to extract URLs from.
    Requis: Oui
Retourne:
  • (string[]) Array of URLs found in passed string.
Défini(e) dans:
Codex:
Changelog:
  • 6.0.0

Uses RegEx to extract URLs from arbitrary content.



Source

function wp_extract_urls( $content ) {
	preg_match_all(
		"#([\"']?)("
			. '(?:([\w-]+:)?//?)'
			. '[^\s()<>]+'
			. '[.]'
			. '(?:'
				. '\([\w\d]+\)|'
				. '(?:'
					. "[^`!()\[\]{}:'\".,<>«»“”‘’\s]|"
					. '(?:[:]\d+)?/?'
				. ')+'
			. ')'
		. ")\\1#",
		$content,
		$post_links
	);

	$post_links = array_unique(
		array_map(
			static function ( $link ) {
				// Decode to replace valid entities, like &amp;.
				$link = html_entity_decode( $link );
				// Maintain backward compatibility by removing extraneous semi-colons (`;`).
				return str_replace( ';', '', $link );
			},
			$post_links[2]
		)
	);

	return array_values( $post_links );
}