putnamehere Posted March 13, 2006 Share Posted March 13, 2006 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? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 13, 2006 Share Posted March 13, 2006 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] Quote Link to comment Share on other sites More sharing options...
putnamehere Posted March 14, 2006 Author Share Posted March 14, 2006 Thats Fantastic!, i'm very pleased.do you take USD or GBP? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.