Jump to content

Archived

This topic is now archived and is closed to further replies.

putnamehere

my website search

Recommended Posts

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??
[code]
<?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.";
}

?>
[/code]
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?

Share this post


Link to post
Share on other sites
Something like


[code]$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";
}[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.