Languages: English • Français • (Add your language)
Use RegEx to extract URLs from arbitrary content.
<?php wp_extract_urls( $content ) ?>
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' )
wp_extract_urls() is located in wp-includes/functions.php
.