通过php解析图像 - 重复问题

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.

$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 '<img src="'. $arr[0] . '" /><br /><br />';
    }

Here is what it does for the first uploaded image:
http://domain.com/server/php/files/filename.jpg
Here is what it does for the second uploaded image:
http://domain.com/server/php/files/filename http://(1).jpg

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

in your post there are two question :

  1. How to read spaces in url answer : you can use urlencode() function.

  2. naming convention for file there may be following options :

a. either don't allow space in file name . remove space with the help of regex

b. either check the file name first in db, if it exist then append 1 or 2 in filename.

if you have any question, let me know