douhui8025 2012-06-27 17:21
浏览 5

通过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.

  • 写回答

1条回答 默认 最新

  • dtla92562 2012-06-27 17:30
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法