WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp extract urls

Description

Use RegEx to extract URLs from arbitrary content.

Usage

<?php wp_extract_urls$content ?>

Parameters

$content
(string) (required) Arbitrary content.
Default: None

Return Values

(array) 
URLs found in passed string.

Examples

This Code:

$string = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin elementum quis lacus in accumsan. Sed sed lacus odio. Sed ullamcorper, nibh et dignissim convallis, lacus tellus pellentesque ipsum, et interdum purus urna ultricies justo. Phasellus blandit eros nec lectus vestibulum consequat. Cras faucibus turpis sed ante commodo cursus. Duis vitae ligula vulputate, varius mi vel, facilisis est. Nulla id mollis ipsum. Nunc faucibus augue vel erat luctus sodales. Curabitur gravida vulputate nulla sed aliquam. Ut posuere mollis mauris, et placerat diam cursus vitae. Vivamus eros arcu, lobortis id sapien at, tempus tristique nunc. Praesent sollicitudin vulputate lorem, vitae vestibulum nisi pretium non. http://example.com is a cool site.';

$urls = wp_extract_urls( $string );

Will return an array like this:

array( 0 => 'http://example.com' )

Change Log

Source File

wp_extract_urls() is located in wp-includes/functions.php.

Related

See also index of Function Reference and index of Template Tags.