php正则替换怎样把 href=http://24356>替换成href=http://24356.xxx.com>

解决方案 »

  1.   

    是固定格式吗?
    固定格式怎么不用str_replace('http://24356', 'http://24356.xxx.com', $content);如果非固定格式preg_repalce('href="?http://([^/".]+)"?', 'href="http://$1.xxx.com"', $content);
      

  2.   


    是变动的 ,不过你的这个用不了 提示错误Delimiter must not be alphanumeric or backslash 
    preg_repalce 这个拼写更正后测试的
      

  3.   

    如果后面的xxx是固定的那么就只要在后面用.连接上域名就可以了啊何必用正则呢?
      

  4.   


    preg_repalce('#href="?http://([^/".]+)"?#i', 'href="http://$1.xxx.com"', $content);需要加一个正则分割符号,我以为你知道呢
      

  5.   

    $str = 'php正则替换怎样fdsfds把 href=http://24356>fsdfdsfd>sfds';$str2 = preg_replace('/href=http:\/\/(.*?)>/i', "href=http://$1.xxx.com>", $str);