腦友記廣場 -> 新手上路 -> 辛假期 登錄 -> 註冊 -> 回復主題 -> 發表主題

yuenlong 2006-08-20 18:54
上路中, 又係時候開一個新手上路,

www.weekendhk.com

飲食主題的 pull down menu
contents/global/sa_bed52a79-55a2-4e41-9f30-61504d1b8aab.js

見佢的內容分曬 fields ,諗緊點樣合番埋 ....

本來弄到個 index page
http://www........../weekend.php


但係詳細內容,裡頭全部係由 javascript 轉接著,詳細內容飛到另一個 javascript,跟著好亂,唔知點算好啊。

http://www.weekendhk.com/contents/20060727/art639c9263-c56d-4d11-ac85-f3e0a2227c3e.js

maninnet 2006-08-20 22:52
就以飲食主題為例, 其目錄放在:
http://www.weekendhk.com/contents/global/sa_bed52a79-55a2-4e41-9f30-61504d1b8aab.js

同樣, 制作一個目錄同一個文章內容, weekend.php, wkview.php, 由於目錄同內容都放在 js 檔, 以前的方法, 並不適用, 不過, 處理 js 檔還比較簡單, weekend.php 處理方法如下:

<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<html><head><title>Weekend HK</title></head>
<body>
Weekend HK
<hr>
<?

$requesturl="http://www.weekendhk.com/contents/global/sa_bed52a79-55a2-4e41-9f30-61504d1b8aab.js";

if ($fp = fopen("$requesturl", "r"))
{
  while(!feof($fp))
  {
    $line = fgets($fp,256);
    if (eregi("{id",$line))
    {
    $line = ereg_replace("[\{\', ]","",$line);
    $line = ereg_replace("id:","",$line);
    $id = trim($line);
    }
    if (eregi("issue",$line))
    {
    $line = ereg_replace("[\', ]","",$line);
    $line = ereg_replace("issue:","",$line);
    $issue = trim($line);
    }
    if (eregi("section_id",$line))
    {
    $line = ereg_replace("[\', ]","",$line);
    $line = ereg_replace("section_id:","",$line);
    $section_id = trim($line);
    }
    if (eregi("topic1",$line))
    {
    $line = ereg_replace("[\', ]","",$line);
    $line = ereg_replace("topic1:","",$line);
    $topic1 = trim($line);
    }
    if (eregi("intro",$line))
    {
    $line = ereg_replace("[\', ]","",$line);
    $line = ereg_replace("intro:","",$line);
    $intro = trim($line);
    echo("<a href=wkview.php?action=article&s=".$section_id."&i=".$issue."&a=".$id."><b>".$topic1."</b></a><br>".$intro."<br><br>\n");
    }

  }

  fclose($fp);
}
?>
<hr>
WeekEnd Hong Kong 1.0
</body></html>

maninnet 2006-08-20 22:58
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
註明用 utf-8

由於用 fgets 係每行讀取, 所以檢視每行有什麼內容, 只有特定內容, 就用特定的方法處理:

  if (eregi("{id",$line))
  {
  $line = ereg_replace("[\{\', ]","",$line);
  $line = ereg_replace("id:","",$line);
  $id = trim($line);
  }
檢查有沒有 {id 這個字元, 有就除去 { ' , 用 $id 儲存作以後使用.

  if (eregi("issue",$line))
  {
  $line = ereg_replace("[\', ]","",$line);
  $line = ereg_replace("issue:","",$line);
  $issue = trim($line);
  }
檢查有沒有 issue 這個字元, 有就除去 ' , 用 $issue 儲存作以後使用.

餘類推, 最後是 intro, 用前法處理 intro 後要作輸出
  echo("<a href=wkview.php?action=article&s=".$section_id."&i=".$issue."&a=".$id."><b>".$topic1."</b></a><br>".$intro."<br><br>\n");

maninnet 2006-08-20 23:05
在 wkview.php 內, 由 weekend.php 傳來的參數要定義:

<body>
<?
$id=$_GET['id'];
$issue=$_GET['issue'];
$section_id=$_GET['section_id'];

之後要找到真正的 url:

$requesturl = "http://www.weekendhk.com/contents/".$issue."/art".$id".".js";

用回 weekend.php 方法, 再組織有關內容.

yuenlong 2006-08-24 00:21
QUOTE:
下面是引用maninnet於2006-08-20 22:52發表的:
就以飲食主題為例, 其目錄放在:
http://www.weekendhk.com/contents/global/sa_bed52a79-55a2-4e41-9f30-61504d1b8aab.js

同樣, 制作一個目錄同一個文章內容, weekend.php, wkview.php, 由於目錄同內容都放在 js 檔, 以前的方法, 並不適用, 不過, 處理 js 檔還比較簡單, weekend.php 處理方法如下:

.......



原來可以 keep 住著 d 資料入去 $ 度,我之前還寫左個笨拙的 codes

QUOTE:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新假期</title>
</head>
<body>
新 假 期<br>
<hr><br>
<?
$wkndview = "wkndview.php";
$homeurl = "http://www.weekendhk.com";
$articleurl = "http://www.weekendhk.com/index.php?action=article&s=bed52a79-55a2-4e41-9f30-61504d1b8aab";
$requesturl = "http://www.weekendhk.com/contents/global/sa_bed52a79-55a2-4e41-9f30-61504d1b8aab.js";
if ($fp = fopen("$requesturl","r")){
while(!feof($fp))
{
$layer = $layer.fgets($fp,256);
}
fclose($fp);
}
eregi("\{items:\[(.*)com.newmedia.ArtCountryList",$layer,$matches);
$layer=$matches[1];
$allowed_tags = "<a>,<b>,<center>,<ul>,<li>,<br>";
$layer=eregi_replace("',","",$layer);
$layer=eregi_replace("        ","",$layer);
$layer=eregi_replace("\{id:'","<br><a href=\"$wkndview?a=",$layer);
#$layer=eregi_replace("\{id:'","<br><a href=\"$articleurl&a=",$layer);
$layer=eregi_replace("issue:'","&i=",$layer);
$layer=eregi_replace("image:'","\"><br><img src=\"$homeurl",$layer);
$layer=eregi_replace("section_id: '","\"><! ",$layer);
$layer=eregi_replace("topic1:'",">",$layer);
$layer=eregi_replace("topic2:'","</a><br>",$layer);
$layer=eregi_replace("intro:'","",$layer);
$layer=eregi_replace("country:","<!",$layer);
$layer=eregi_replace("city:","<!",$layer);
$layer=eregi_replace("\}\}",">",$layer);
$layer=eregi_replace("]\}","",$layer);



#$layer=ltrim($layer);
#$layer=rtrim($layer);
$layer = strip_tags($layer, $allowed_tags);
$layer="".$layer."";
echo($layer);
?>
<br><br>
powered by ManInNet
</body></html>


等我完成埋個 view 先 ... thanks Maninnet

yuenlong 2006-09-04 23:51
個 trim 都有點問題,文章中刪走了 <BR/> 都會出現一點位排位問題

yuenlong 2006-09-07 10:48
都被文章裡頭這個 <BR/> 煩倒了,試過把 <BR/> 轉為 <BR>,但係全句就到此為止,

也用上了新手上路之前所教的 Ltrim, Rtrim,不知點解部份內容出現少少亂碼 .... 要繼續摸索一下


QUOTE:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>新假期</title>
</head>
<body>
新 假 期<br>
<hr><br>
<?
$homeurl = "http://www.weekendhk.com";
$date=$_GET['i'];
$article = $_GET['a'];
$requesturl = "http://www.weekendhk.com/contents/$date/art$article.js";
echo($requesturl);
if ($fp = fopen("$requesturl", "r"))
{
while(!feof($fp))
{
  $line = fgets($fp,256);

  if (eregi("topic",$line))
  {
  $line = ereg_replace("[\', ]","",$line);
  $line = ereg_replace("topic:","",$line);
  $line = ereg_replace("<br/>","<br>",$line);
  $topic = ltrim($line);
  $topic = rtrim($line);
  echo("<br>");
  echo($topic);
  echo("<br>");
  }
  if (eregi("intro",$line))
  {
  $line = ereg_replace("[\', ]","",$line);
  $line = ereg_replace("intro:","",$line);
  $line = ereg_replace("<br/>","<br>",$line);
  $intro = ltrim($line);
  $intro = rtrim($line);
  echo("<br>");
  echo($intro);
  echo("<br>");
  }
  if (eregi("heading",$line))
  {
  $line = ereg_replace("[\', ]","",$line);
  $line = ereg_replace("heading:","",$line);
  $line = ereg_replace("<br/>","<br>",$line);
  $heading = ltrim($line);
  $heading = rtrim($line);
  echo("<br>");
  echo($heading);
  echo("<br>");
  }
  if (eregi("content",$line))
  {
  $line = ereg_replace("[\', ]","",$line);
  $line = ereg_replace("content:","",$line);
  $line = ereg_replace("<br/>","<br>",$line);
  $content = ltrim($line);
  $content = rtrim($line);
  echo("<br>");
  echo($content);
  echo("<br>");
  }
  if (eregi("{id",$line))
  {
  $line = ereg_replace("[\{\', ]","",$line);
  $line = ereg_replace("id:","",$line);
  $line = ereg_replace("<br/>","<br>",$line);
  $id = ltrim($line);
  $id = rtrim($line);
  }
}
fclose($fp);


}
?>

greatwall 2006-09-14 13:41
yuenlong 兄,技術問題解决了沒有?正期侍最後成品。謝謝。
PS. 我都想學寫 php scripts, Man 兄的解說很好,可惜資質有限,攪來攪去攪不成。


查看完整版本: [-- 辛假期 --] [-- top --]


Powered by PHPWind v4.0.1 Code © 2003-05 PHPWind
Gzip enabled

You can contact us