View Full Version : Page search

08-02-2007, 08:11 PM
Hi guys! For some time agi I saw a thread where 2 people both posted their search scritps, and one said that his was faster than the other. However now I can't find that thread, so I'll ask again:

How do I make a search script that will, when you enter a keyword into the search field and press search, highlight the word(s) on the page?

08-02-2007, 08:18 PM
Here's the thread

Scan a page (http://www.codingforums.com/showthread.php?t=120097)

Smthing like this (http://jasamza.korisnik.com/misc/codingforums/)

08-04-2007, 10:37 AM
Thanks Matak, for the script! But...Again I have a problem.

For reference, this is my searchscript.php file:

$uzorak = $_POST['query'];
//use post to get $uzorak variable

$tapeti = file_get_contents("frequsedwords.php");

$tagovi = array();

work ($uzorak, $tapeti);
function work($uzorak, $tapeti) {

$duzina = strlen($uzorak);
$velicina = strlen($tapeti);

$b = array();
$a = 0;
while ($a <= $velicina){
$newstr = substr($tapeti, $a, $duzina);

if ($newstr == $uzorak){
$tagovi[]= $a;
elseif ($a == $velicina && !empty($tagovi)){
uredi_tagove($tagovi, $tapeti, $duzina);
elseif ($a == $velicina && empty($tagovi)) {
echo "sorry no matches found";
function uredi_tagove($tagovi, $tapeti, $duzina){

$newstring ="";
$count = count($tagovi);
$nextchar = 0;
for($i = 0;$i<$count;$i++)
$newstring .= substr($tapeti,$nextchar,$tagovi[$i]-$nextchar);
$newstring .= "<strong>". substr($tapeti,$tagovi[$i],$duzina) ."</strong>";
$nextchar = $tagovi[$i]+$duzina;
$newstring .= substr($tapeti,$nextchar);
print $newstring;


And this is my form HTML code:

<form action="searchscript.php" method="POST" >
<input type="text" name="query" >
<input type="submit" value="search" >

The problem is, that when I input a word like "FMC" and press search, nothing happens other than the word dissapears and the calender I have on the left hand site only shows some code. Try it out here: http://www.xflightx.port10.com/frequsedwords.php

I only want the script to highlight the word I search for, nothing else.

08-04-2007, 10:49 AM
for me when i press submit it brings up so no matches

08-04-2007, 12:22 PM
First script is caps sensitive, that can be changed with using strtolower() (http://www.php.net/manual/en/function.strtolower.php) function.

Test it first with using some text file and getting it with file_get_contents, and make sure that path for file get contents is correct.

Other than that i can't see the problem, couse for me script works just fine

08-04-2007, 08:21 PM
Hi again!

I found that this wasn't quite the script I was looking for... (thanks for the try, Matak).

So, I have found another one. I'll continue here: http://www.codingforums.com/showthread.php?p=596495#post596495

Thanks for the help, guys!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum