0
我有模型WikiPage。 WikiPage->我從數據庫中獲得文本。我做了方法「wikify」,並通過class :: wikify($ Page-> getText())在頁面上生成文本。 在文本我有建設[鏈接名],我生成的鏈接與此:維基風格的鏈接。如果目標頁面不存在,如何更改鏈接的顏色
$text = preg_replace('@\[(.*) (.*)\]@', '<a href="\\1" class="<?php Wiki::httpresponse($\\1) ?>">\\2</a>', $text);
的想法是檢查與功能的HttpResponse和變化類的網址,如果沒有頁面。
httpresponce:
static public function httpresponse($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_exec ($ch);
$intReturnCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ($intReturnCode != 200 && $intReturnCode != 302 && $intReturnCode != 304) { return "red"; } else return "blue";
}
2個問題:
當我測試httpresponce在我的本地網頁它不容易找到他們,當我測試它在網頁上,一切正常。
(如
http://localhost:8080/category/page
檢查鏈接,類別:第一模塊,頁面isecond,主頁是模塊:類別,動作:指數類/頁是模塊路徑:頁面,動作:秀)類生成的鏈接仍然爲
<?php Wiki::httpresponse($\\1) ?>
方法httpresponce未執行。
可以做些什麼? 也許有更好的方法來完成這項任務?
不要忘記接受你自己的答案 – j0k 2013-02-25 08:26:32