Retrieving all Links from a Post?

I’ll answer your question below, but have you looked at using embeds? Look here for more information: http://codex.wordpress.org/Embeds

The simplest regex for this would look something like http\:\/\/.*\b

Here’s an example of it in action:

<?php 

$file="test.txt";

$fp = fopen($file, 'r');

$contents = fread($fp, filesize($file));

$matches = array();

preg_match_all('/http\:\/\/.*\b/', $contents, $matches);

print_r($matches);

?>

Where the file I reference looks like this:

http://wordpress.stackexchange.com/questions/12809/retrieving-all-links-from-a-post

http://www.youtube.com/

http://ca3.php.net/manual/en/function.preg-match.php

and the return looks like this:

Array
(
    [0] => Array
        (
            [0] => http://wordpress.stackexchange.com/questions/12809/retrieving-all-links-from-a-post
            [1] => http://www.youtube.com
            [2] => http://ca3.php.net/manual/en/function.preg-match.php
        )

)