พบกับบทความเกี่ยวกับคอมพิวเตอร์และ programming ได้ที่ http://articles.modoeye.com
Javascript development / รบกวนสอบถามวิธีการทำเสริตในเว็บนะครับ
รุต
รุต
Mon 16 Jan 2006 08:38:25

รบกวนสอบถามวิธีการทำเสริตภายในเว็บของเราเองทั้งหมดนะครับ  แบบเก็บฐานข้อมูลเว็บเป็นtextfileนะครับ
ตัวอย่าง  คือ index.html  ในหน้านี้จะประกอบด้วย หัวข้อ
   test1  =  www.test.com/test1.html
   test2  =  www.test.com/test1.html
ถ้าให้เสริตหาtest1 และtest2ภายในเว็บนะครับ

ขอบคุณมากครับ

Administrator
Mon 16 Jan 2006 11:16:24
ถ้าคุณไม่ได้ใช้ฐานข้อมูลนั้นก็ให้ใช้ Server-side script นั้นอ่านนข้อมูลจากไฟล์ทั้งหมดลงตัวแปร แล้วทำการค้นหาข้อมูลในนั้นด้วยการใช้ฟังก์ชั่น index string เช่น strstr ใน c, php, perl หรือ indexOf ใน java ว่ามีตัวอักษรตาม pattern หรือไม่ครับ

ปัญหาของระบบนี้คือ ถ้ามีไฟล์ที่ต้องการค้นหาหลายๆไฟล์ จะเกิด Script execution Time-out ครับเนื่องจากการทำงานแบบนี้จะค่อนข้างช้าถึง ช้ามากครับ
รุต
รุต
Mon 16 Jan 2006 12:45:24

รบกวนขอโค้ดตัวอย่างบ้างครับ  คือถ้า  ผมมีเว็บ  สัก2-3หน้า  แล้วมีหัวข้อที่ต้องการค้นคือ test1(127.0.0.1/test1.html)  กับ  test2(127.0.0.1/test2.html)  ซึ่งทั้ง2มะรู้อยู่หน้าไหนของเว็บเพจทั้งหมด ซึ่งจะมีtextbox เพื่อให้คีหาข้อมูลในเว็บจะอยู่หน้าแรก และมีปุ่มเสริตเพื่อกดค้นหาข้อมูลภายในเว็บ อยากเก็บฐานข้อมูลที่จะใช้ค้นให้อยู่ในรูปของtextfileครับ

รบกวนด้วยนะครับ 
ขอบคุณมากครับ

Administrator
Mon 16 Jan 2006 14:13:11
<?
$pat = "คำที่ต้องการค้นหา"; //ทำการ assign ค่าคำที่ต้องการใช้ในการค้นหาเก็บไว้ในตัวแปร $pat
$f = file_get_content("test1.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test1.html
$test1 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">${1}</span>", $f); //ค้นหาและทำการ hilight ข้อความที่ค้นเจอ
echo $test1; // แสดงผล

$f = file_get_content("test2.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test1.html
$test2 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">${1}</span>", $f);
echo $test2;
?>
รุต
รุต
Fri 20 Jan 2006 10:01:45

รบกวนขอโค้ดเพิ่มทีครับ  คือผมมะรู้ว่าจะไปสร้างเพจอย่างไรบ้างนะครับ แล้วมะรู้ว่าจะเอาโค้ดไปใส่อย่างไร

    คือถ้าผมมีเพจ  test1.html  test2.html   test3.html

test1.htmlจะเป็นหน้าแรก และเป็นหน้าที่link  test2.htmlและtest3.html

ให้หน้าtest1.htmlมีtextboxและปุ่มสำหรับค้นหาข้อมูลภายในเว็บทั้งหมดรวมถึงหน้าtest2และtest3.html  test1ผมต้องใส่โค้ดอย่างไรบ้างครับ  สมมุตข้อมูลที่ต้องการค้นเป็นหัวข้อที่มันไปอยู่ในหน้าtest2.html  ชื่อ  บทความ

ผมอยากเก็บฐานข้อมูลเป็นแบบtextfileได้ไหมครับ

รบกวนด้วยนะครับ

ขอบคุณมากครับ

Administrator
Sat 21 Jan 2006 22:48:28
ทำการสร้าง form ที่มี textbox ชื่อ q และปุ่ม submit
ส่วนในไฟล์ที่รับค่าก็ใส่ดังข้างล่างครับ

<?
$pat = $_POST["q"]; //ทำการ assign ค่าคำที่ต้องการใช้ในการค้นหาเก็บไว้ในตัวแปร $pat
$f = file_get_content("test1.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test1.html
$test1 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">${1}</span>", $f); //ค้นหาและทำการ hilight ข้อความที่ค้นเจอ
echo $test1; // แสดงผล

$f = file_get_content("test2.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test1.html
$test2 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">${1}</span>", $f);
echo $test2;
?>

เข้าใจว่าจะเก็บข้อมูลทั้งหมดในรูปแบบ textfile นั้นทำได้ครับแต่ว่า performance ที่ได้ก็ไม่ต่างกันครับ
รุต
รุต
Mon 23 Jan 2006 14:40:09

รบกวนอีกนิดครับ คือผมลองเอาโค้ดด้านบนลองไปทำดูแล้วมะได้นะครับ  คือผมไม่รู้ว่าจะไปเริ่มสร้างเพจอย่างไรบ้าง

อันนี้คือเพจtest1.html จะมีtestboxชื่อq  ให้เพจtest1.htmlสามารถค้นtest2.htmlและtest3.htmlได้ด้วยนะครับ  ผมต้องใส่โค้ดอย่างไงบ้างครับ

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=Content-Type content=text/html; charset=windows-874">
</head>

<body>
<form name="form1" method="post" action="test1.php">
  <input name="q" type="text" id="q">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

----------------------------------------------------------------

อันนี้คือเพจtest2.html

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>

<body>
<p>test</p>
<p>test2</p>
<p>test3</p>
<p>test4 </p>
</body>
</html>

-------------------------------------------------

test3.html

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>

<body>
<p>บทความที่1</p>
<p>บทความที่2</p>
<p>บทความที่3</p>
</body>
</html>

รบกวนด้วยนะครับ

ขอบคุณมากครับ

Administrator
Mon 23 Jan 2006 20:43:15

สมมติว่านี่คือข้อมูลของ test1.html

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=Content-Type content=text/html; charset=windows-874">
</head>

<body>
<form name="form1" method="post" action="search.php">
  <input name="q" type="text" id="q">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>


นี่คือ search.php
<?
$pat = $_POST["q"]; //ทำการ assign ค่าคำที่ต้องการใช้ในการค้นหาเก็บไว้ในตัวแปร $pat
$f = file_get_content("test1.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test1.html
$test1 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">${1}</span>", $f); //ค้นหาและทำการ hilight ข้อความที่ค้นเจอ
echo $test1; // แสดงผล

$f = file_get_content("test2.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test2.html
$test2 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">${1}</span>", $f);
echo $test2;

$f = file_get_content("test3.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test3.html
$test3 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">${1}</span>", $f);
echo $test3;
?>

ประมาณนี้ครับ
รุต
รุต
Wed 25 Jan 2006 12:17:59

รบกวนอีกนิดนึงครับ  คือผมลองเอาโค้ดมารันดู ผมรันtest1.html แล้วใส่คำเสริตว่าtest  แล้วส่งค่าไปที่search.php  มันก็ขึ้นerror โค้ดด้านล่างนี้  fileที่ประกอบการtestมีtest1.html(ตามโค้ดที่ให้)   test2.html  test3.html  search.php(ตามโค้ดที่ให้)
 

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in c:\appserv\www\roott\search.php on line 4

รบกวนแก้ให้ทีครับ

ขอบคุณมากครับ

Administrator
Wed 25 Jan 2006 13:15:08
<?
$pat = $_POST["q"]; //ทำการ assign ค่าคำที่ต้องการใช้ในการค้นหาเก็บไว้ในตัวแปร $pat
$f = file_get_content("test1.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test1.html
$test1 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">\\1</span>", $f); //ค้นหาและทำการ hilight ข้อความที่ค้นเจอ
echo $test1; // แสดงผล

$f = file_get_content("test2.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test2.html
$test2 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">\\1</span>", $f);
echo $test2;

$f = file_get_content("test3.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test3.html
$test3 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">\\1</span>", $f);
echo $test3;
?>

โทษทีครับด้นผิดไปหน่อย
รุต
รุต
Wed 25 Jan 2006 14:08:05

ขอโทษนะครับมันยังติดerrorอยู่เลยนะครับ

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in c:\appserv\www\roott\search.php on line 4

fileที่ใช้

search.php

<?
$pat = $_POST["q"]; //·Ó¡Òà assign ¤èÒ¤Ó·Õèµéͧ¡ÒÃãªé㹡Òäé¹ËÒà¡çºäÇéã¹µÑÇá»Ã $pat
$f = file_get_content("test1.html"); //ÍèÒ¹¢éÍÁÙÅ·Ñé§ËÁ´ã¹ä¿Åì test1.html
$test1 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">\\1</span>", $f); //¤é¹ËÒáÅзӡÒà hilight ¢éͤÇÒÁ·Õè¤é¹à¨Í
echo $test1; // áÊ´§¼Å

$f = file_get_content("test2.html"); //ÍèÒ¹¢éÍÁÙÅ·Ñé§ËÁ´ã¹ä¿Åì test2.html
$test2 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">\\1</span>", $f);
echo $test2;

$f = file_get_content("test3.html"); //ÍèÒ¹¢éÍÁÙÅ·Ñé§ËÁ´ã¹ä¿Åì test3.html
$test3 = preg_replace("/(".$pat".)/i","<span style=\"font-weight:bold; color:#FF0000;\">\\1</span>", $f);
echo $test3;
?>

--------------------------------------------------------

test1.html

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=Content-Type content=text/html; charset=windows-874">
</head>

<body>
<form name="form1" method="post" action="search.php">
  <input name="q" type="text" id="q">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

------------------------------------------

อันนี้คือเพจtest2.html

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>

<body>
<p>test</p>
<p>test2</p>
<p>test3</p>
<p>test4 </p>
</body>
</html>

-------------------------------------------------

test3.html

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
</head>

<body>
<p>บทความที่1</p>
<p>บทความที่2</p>
<p>บทความที่3</p>
</body>
</html>

รบกวนด้วยนะครับ

ขอบคุณมากครับ

Administrator
Wed 25 Jan 2006 14:37:56
<?
$pat = $_POST["q"]; //ทำการ assign ค่าคำที่ต้องการใช้ในการค้นหาเก็บไว้ในตัวแปร $pat
$f = file_get_contents("http://www.modoeye.com"); //อ่านข้อมูลทั้งหมดในไฟล์ test1.html
$test1 = preg_replace("/($pat)/i",'<span style="font-weight:bold; color:#FF0000;">\\1</span>', $f); //ค้นหาและทำการ hilight ข้อความที่ค้นเจอ
echo $test1; // แสดงผล

$f = file_get_contents("test2.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test2.html
$test2 = preg_replace("/($pat)/i","<span style=\"font-weight:bold; color:#FF0000;\">\\1</span>", $f);
echo $test2;

$f = file_get_contents("test3.html"); //อ่านข้อมูลทั้งหมดในไฟล์ test3.html
$test3 = preg_replace("/($pat)/i","<span style=\"font-weight:bold; color:#FF0000;\">\\1</span>", $f);
echo $test3;
?>

ตามนี้เลยครับ
รุต
รุต
Wed 25 Jan 2006 16:46:40

รบกวนอีกนิดนึงครับ  ผมลองเอาโค้ดด้านบนไปลองทำดูแล้ว ผมลองใส่ข้อมูลที่ต้องการค้น ถ้ามีข้อมูลที่คีลงไป มันจะทำให้ข้อมูลนั้นเป็นสีแดง  และโชข้อมูลทั้งหมดใน  test2.html และโชข้อมูลในtest3.html  แต่ถ้าค้นมะเจอเลยมันก็จะโช  ข้อมูลทั้งหมดที่มีใน  test2.html  และtest3.html   รบกวนขอแบบถ้าค้นเจอให้เปิด หน้านั้นขึ้นมาแล้วก็ให้ไฮไลที่ข้อความที่เจอครับ

ถ้าไม่เจอให้โชข้อความว่ามะมี  ข้อความที่ค้น

รบกวนด้วยนะครับ

ขอบคุณมากครับ

รุต
รุต
Thu 26 Jan 2006 13:25:26

รบกวนอีกนิดนึงครับ  ผมลองเอาโค้ดด้านบนไปลองทำดูแล้ว ผมลองใส่ข้อมูลที่ต้องการค้น ถ้ามีข้อมูลที่คีลงไป มันจะทำให้ข้อมูลนั้นเป็นสีแดง  และโชข้อมูลทั้งหมดใน  test2.html และโชข้อมูลในtest3.html  แต่ถ้าค้นมะเจอเลยมันก็จะโช  ข้อมูลทั้งหมดที่มีใน  test2.html  และtest3.html   รบกวนขอแบบถ้าค้นเจอให้เปิด หน้านั้นขึ้นมาแล้วก็ให้ไฮไลที่ข้อความที่เจอครับ

ถ้าไม่เจอให้โชข้อความว่า "มะมีข้อความที่ค้น"

รบกวนด้วยนะครับ

ขอบคุณมากครับ

Administrator
Thu 26 Jan 2006 14:58:11
อืม ถ้าต้องการให้เปิดหน้าแล้ว hilight ด้วยคงต้องใช้ Javascript ช่วยครับ แต่ขอหาก่อน (จำไม่ได้เอาไปไว้ไหนแล้ว)
รุต
รุต
Thu 26 Jan 2006 15:55:23

รบกวนด้วยนะครับ

ขอบคุณมากครับ

รุต
รุต
Fri 27 Jan 2006 09:12:31

รบกวนขอโค้ดบ้างนะครับ  อยากได้มากๆครับ

ขอบคุณมากครับ

รุต
รุต
Fri 27 Jan 2006 16:10:40

รบกวนหาให้บ้างนะครับ

รบกวนด้วยนะครับ

ขอบคุณมากครับ

รุต
รุต
Sat 28 Jan 2006 08:59:46

รบกวนขอโค้ดบ้างนะครับ  อยากได้มากๆครับ

ขอบคุณมากครับ

รุต
รุต
Sat 28 Jan 2006 09:08:41

ผมลองเข้าไปเว็บที่ให้มาแล้วนะครับ   เข้าไปแล้วงงมะรู้จะเริ่มทำตรงไหนดีเลย  รบกวนขอโค้ดจากAdministrator ดีกว่า   ในเว็บที่ให้มา เข้าไปดูแล้วคอนฟิกมะถูกมะรู้จะทำไงเลย

รบกวนด้วยนะครับ

ขอบคุณมากครับ

รุต
รุต
Tue 31 Jan 2006 09:31:37

รบกวนขอโค้ดบ้างนะครับ  อยากได้มากๆครับ

ขอบคุณมากครับ

Administrator
Tue 31 Jan 2006 11:17:47
ขอโทษด้วยครับที่ตอบช้า
จากลิงค์ที่ให้ไปนั้น เพียงใส่
ไว้ในหน้าเอกสารนั้นๆเท่านั้นครับ ซึ่งแน่นอนว่าคงต้องมีการแก้ไขโค๊ดบางอย่าง เพื่อให้ตรงตามที่คุณต้องการด้วยครับ
รุต
รุต
Tue 31 Jan 2006 13:43:29

ขอโทนะครับ  ผมลองเอามาใส่ดูแล้วครับ  แล้วมันมะได้นะครับ  อาจจะทำมะถูกวิธีก็ได้

รบกวนขอตัวอย่างนิดนึงครับ

รบกวนด้วนะครับ

ขอบคุณมากครับ

Reply
Name:
E-mail:
Home | Services | Forum | Classified | Directories | Support | Contact
ATOM feed RSS 0.9 feed RSS 1.0 feed RSS 2.0 feed
Copyright © 2005 - 2007 Modoeye.com, All Rights Reserved.
Disclaimer | Privacy policy | Term of Use | Term of Services
Valid XHTML Valid CSS! PHP: Hypertext Preprocessor MySQL database Apache Powered! FreeBSD Power to serve
Modoeye Sitemap Client login