2012-12-31 54 views
0

我正在網站中構建字典。我將這些術語的原始網站(www.rae.es)定義稱爲「自己的CSS」。這裏是代碼:重定向兩次到網站

<?php 
    $word = $_REQUEST['word']; 


    $url = "http://lema.rae.es/drae/srv/search?val={$word}"; 

    $css = <<<EOT 

    <style type="text/css"> 
    @font-face { 
       font-family: 'brannboll_fetregular'; 
       src: url('brannbollfet-webfont.eot'); 
       src: url('brannbollfet-webfont.eot?#iefix') format('embedded-opentype'), 
        url('brannbollfet-webfont.woff') format('woff'), 
        url('brannbollfet-webfont.ttf') format('truetype'), 
        url('brannbollfet-webfont.svg#brannboll_fetregular') format('svg'); 

       } 

    .a 
     { 
     color: #ffe200; 
     margin-top:20px !important; 
     } 
    .f 
     { 
     margin-left:20px !important; 
     margin-top:10px; 
     font-size: 200%; 
     color: #ffe200; 
     font-family: 'brannboll_fetregular'; 

     } 
    .o 
     { 
     font-size: 80%; 
     color: #ffe200; 
     margin-left:10px; 
     font-family: 'Belgrano', serif; 
     } 
    .q { 
     margin-left:10px; 
     font-family: 'Belgrano', serif; 
     } 
    .k { 
     margin-left:10px; 
     font-family: 'Belgrano', serif; 
     } 
    .p { 

     font-family: 'Belgrano', serif; 
     }  
    img 
     { 
     visibility:hidden; 
     } 

    </style> 
    EOT; 

    $data = file_get_contents($url); 
    $data = str_replace('<head>', $css.'</head>', $data); 
    $data = str_replace('<span class="f"><b>.</b></span>', '', $data); 
    echo '<div id="result1" 
     style=" 
     top: 77%; 
     left: 55%; 
     overflow:scroll; 
     width:400px; 
     height:300px; 
     border: 1px solid #000000; 
     border-radius: 15px; 
     background-opacity: 0.5; 
     background: #047C8F; 
     -webkit-border-radius: 15px; 
     -moz-border-radius: 15px; 
     box-shadow: inset 0px 3px 13px #000000; 
     -moz-box-shadow: 
        0px 3px 13px rgba(000,000,000,0.5), 
        inset 0px 0px 13px rgba(0,0,0,1); 
     -webkit-box-shadow: 
        0px 3px 13px rgba(000,000,000,0.5), 
        inset 0px 0px 13px rgba(0,0,0,1); 
    "> 
    '.$data.' 
    </div>'; 
     ?> 

現在,有時,對於某些單詞,建議出現了。例如:http://lema.rae.es/drae/?val=casa。如果你搜索「casa」,你會想出3條建議。現在,如果在我的網站上,我點擊這些超鏈接,我被重定向到一個錯誤頁面。所以,我現在認爲解決方案是在PHP的手中,我只是不知道從哪裏開始。 謝謝!

回答

0

鏈接指向您的服務器上顯然不存在的文件。您可以將處理請求的內容寫入文件(例如,使用mod_rewrite重寫或nginx「位置」),或者掃描返回的HTML代碼以獲取這些鏈接並在將HTML發送給用戶之前對其進行修復。

你確定你在做什麼是合法的嗎?看起來您正在複製另一個網站的內容並將其作爲您自己的內容傳遞給他人。除非網站明確允許,否則你絕對是而不是應該這樣做。

+0

1)如何「修復」掃描的鏈接。 2)只要我不賺錢就合法合法 – j1nma

+0

找到它們並用指向你的腳本的鏈接替換它們(然後應顯示正確的答案) –

1

如果你看看HTML你http://lema.rae.es/drae/?val=casa得到的,你會看到你的建議鏈接是相對鏈接:

< A HREF = 「?檢索ID = wHzIYMmRVDXX2tX1bpuy」 >

在將它們發送給用戶之前,您應該將它們更改爲絕對鏈接。你可以做這樣的事情:??

< PHP $數據=的preg_replace('/(搜索[\ d \ W] +)/','http://lema.rae.es/drae/ srv/\ 1',$ data)

更好的解決方案是使用DOMParser來解析來自服務器的響應,並使用CSS選擇器或xpath來查找鏈接並重寫它們的href屬性。看看DOMCrawler Symfony component