就是我在某个网页插入了一个php链接我想获得那个网址地址地址栏的url而且要输出txt格式或其他格式。应该如何实现???还有就是写入到.txt 文件里,怎么去判断是否重复。

解决方案 »

  1.   

    <?php 
    if(!file_exists("ceshi.txt")){ 
        fopen("ceshi.txt",'w'); 
    }
    $handle = fopen("ceshi.txt",'a'); 
    $url = "http://".$_SERVER["HTTP_HOST"].(($_SERVER["SERVER_PORT"]==="80")?"":$_SERVER["SERVER_PORT"]).$_SERVER["REQUEST_URI"];
    echo $url."<br>";
    $txt = file_get_contents("ceshi.txt");
    if (!empty($txt)){
        if (preg_match("#".$url."#",$txt)==0){
            fwrite($handle,$url);
        }else{
            echo "已存在地址";
        }
    }else{
        fwrite($handle,$url);
    }
    ?>
      

  2.   

    <?php 
    if(!file_exists("ceshi.txt")){ 
        fopen("ceshi.txt",'w'); 
    }
    $handle = fopen("ceshi.txt",'a'); 
    //获得浏览器地址
    $url = "http://".$_SERVER["HTTP_HOST"].(($_SERVER["SERVER_PORT"]==="80")?"":$_SERVER["SERVER_PORT"]).$_SERVER["REQUEST_URI"];
    echo $url."<br>";
    $txt = file_get_contents("ceshi.txt");
    //写入文件
    if (!empty($txt)){
        if (preg_match("#".$url."#",$txt)==0){
            fwrite($handle,$url);
        }else{
            echo "已存在地址";
        }
    }else{
        fwrite($handle,$url);
    }
    ?>
      

  3.   

    fwrite将字符写入指定的文件
    $file=file_get_contents('a.txt');
    echo $file;
    $string="aaa";
    echo strpos($file, 'a');
    if(strpos($file, 'a')) {
        echo "你要插入的字符串已经存在";
    }else{
        $fp=fopen("a.txt", "w+");
        $string=$file.":".$string;
        fwrite($fp, $string);
    }
    $file=file_get_contents('a.txt');
    echo $file;
    ?>
      

  4.   

    fwrite将字符写入指定的文件
    $file=file_get_contents('a.txt');
    echo $file;
    $string="aaa";
    echo strpos($file, 'a');
    if(strpos($file, 'a')) {
        echo "你要插入的字符串已经存在";
    }else{
        $fp=fopen("a.txt", "w+");
        $string=$file.":".$string;
        fwrite($fp, $string);
    }
    $file=file_get_contents('a.txt');
    echo $file;
    ?>