Parsing images through php - issue with duplicates
<p>So, this is the only issue I am having left to fix on my site. When it fetches a post from the database and is then called to parse/replace the URL as a  it has a problem. The problem is only with duplicates or image names containing a space in them.</p>

<pre><code>$result = mysql_query("SELECT * FROM posts ORDER BY postid DESC");

while($row = mysql_fetch_array($result))
  {

$str = $row['post_content'];

$str = preg_replace_callback('#(?:https?://\S+)|(?:www.\S+)|(?:\S+\.\S+)#', function($arr)
{
    if(strpos($arr[0], 'http://') !== 0)
    {
        $arr[0] = 'http://' . $arr[0];
    }

    $url = parse_url($arr[0]);

    // images
    if(preg_match('#\.(png|jpg|gif)$#', $url['path']))
    {
        return '&lt;img src="'. $arr[0] . '" /&gt;&lt;br /&gt;&lt;br /&gt;';
    }
</code></pre>

<p>Here is what it does for the first uploaded image:<br />
<a href="http://domain.com/server/php/files/filename.jpg" rel="nofollow">http://domain.com/server/php/files/filename.jpg</a><br />
Here is what it does for the second uploaded image:<br />
<a href="http://domain.com/server/php/files/filename" rel="nofollow">http://domain.com/server/php/files/filename</a> http://(1).jpg<br /></p>

<p>I need to either control the naming convention for how names the file or control how it reads the spaces in the URL.</p>
