get_url_in_content

Extract and return the first URL from passed content.

Description

(string|false) get_url_in_content( (string) $content ); 

Returns (string|false)

The found URL.

Parameters (1)

0. $content (string)
A string which might contain a URL.

Usage

  1. if ( !function_exists( 'get_url_in_content' ) ) { 
  2. require_once ABSPATH . WPINC . '/formatting.php'; 
  3.  
  4. // A string which might contain a URL. 
  5. $content = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = get_url_in_content($content); 
  9.  

Defined (1)

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

/wp-includes/formatting.php  
  1. function get_url_in_content( $content ) { 
  2. if ( empty( $content ) ) { 
  3. return false; 
  4.  
  5. if ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) { 
  6. return esc_url_raw( $matches[2] ); 
  7.  
  8. return false;