Jump to content


Photo

my website search


  • Please log in to reply
2 replies to this topic

#1 putnamehere

putnamehere
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 13 March 2006 - 03:07 PM

I would like to creat a script that searched files on my server for a string once the string was found it would desply the area were it found it, how would i do this??
<?php
$search = $_POST['s'];
$file="index.php";
$getcontents=file_get_contents($file);
  

if (preg_match("/$search/", "$getcontents", $look)) {
   echo "A match was found.<BR>$look";
} else {
   echo "A match was not found.";
}

?>
Thats what i'v got so far but it just says a match was found array how would i desply the text after the or before were the string it found?

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 13 March 2006 - 11:57 PM

Something like


$search = $_POST['s'];
$file="index.php";
$getcontents=file_get_contents($file);

if (false !== ($p = strpos ($getcontents, $search))) {

    $s = $p < 50 ? 0 : $p - 50;
    $e = $p + 60;

    $getcontents = substr($getcontents, $s, $e-$s);
    $getcontents = str_replace ($search,  "<SPAN style='background-color: red; color: white'>$search </SPAN>",  $getcontents);

    echo $getcontents;

}
else {
      echo "'$search' not found";
}

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 putnamehere

putnamehere
  • Members
  • Pip
  • Newbie
  • 6 posts

Posted 14 March 2006 - 12:11 AM

Thats Fantastic!, i'm very pleased.
do you take USD or GBP?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users