因为网站要改成伪静态的,所以今天要改一个页面的所有链接,这页面里的链接很多,但格式都一样:../list.php?cid=50000697现在要改成../list-cid-50000697.html
本来打算先把数字前面的替换一下,然后手动添加.html的,但是由于链接非常多,难免出错,而且也很麻烦,这时,看到Dreamweaver的查找和替换中有使用正则表达式这个选项,但我没用过,请问用过的高手,这正则应该怎么写,这个对话框查找/替换是分开的。

解决方案 »

  1.   

    第一回答问题
    你要的正则:
    $string = "../list.php?cid=50000697";  
    $pattern = "/list\.php\?cid=([0-9]+)/"; 
    $replacement = "list-cid-\${1}.html";
    echo preg_replace($pattern, $replacement, $string);不建议这么做 我觉的你在缓冲输出时就更改为伪静态比较好  易于以后的扩展
    例子 (正则匹配参照上面的)
    $content = <<<CONTENT
    <a href="../list.php?cid=50000697">testlink</a>
    CONTENT;echo $content."<br />";$content = ob_get_contents();
    $content = str_replace("list.php?cid=50000697", "list-cid-50000697.html",$content);
    echo $content;
    ob_end_flush();
      

  2.   

     你伪静态    ../list.php?cid=50000697      这个地址不行么!?