wp_extract_urls

Use RegEx to extract URLs from arbitrary content.

Description

(array) wp_extract_urls( (string) $content ); 

Returns (array)

URLs found in passed string.

Parameters (1)

0. $content (string)
Content to extract URLs from.

Usage

  1. if ( !function_exists( 'wp_extract_urls' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.php'; 
  3.  
  4. // Content to extract URLs from. 
  5. $content = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_extract_urls($content); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.php  
  1. function wp_extract_urls( $content ) { 
  2. preg_match_all( 
  3. "#([\"']?)(" 
  4. . "(?:([\w-]+:)?//?)" 
  5. . "[^\s()<>]+" 
  6. . "[.]" 
  7. . "(?:" 
  8. . "\([\w\d]+\)|" 
  9. . "(?:" 
  10. . "[^`!()\[\]{};:'\"., <>****\s]|" 
  11. . "(?:[:]\d+)?/?" 
  12. . ")+" 
  13. . ")" 
  14. . ")\\1#",  
  15. $content,  
  16. $post_links 
  17. ); 
  18.  
  19. $post_links = array_unique( array_map( 'html_entity_decode', $post_links[2] ) ); 
  20.  
  21. return array_values( $post_links );