need help for customizing PHP-grep files search

can somebody please help me with this issue...

i have installed PHP-grep on my website and it works well.. but that i need a little change in the script so that it displays the file with hyperlink in it instead of displaying the actual path.

would be really helpful if somebody help me..
below is the code that i have in my site www.linktoprofessionals.com/files

<?php

/**
* powered by @cafewebmaster.com
* free for private use
* please support us with donations
*/

define("SLASH", stristr($_SERVER[SERVER_SOFTWARE], "win") ? "\\" : "/");

$path = ($_POST[path]) ? $_POST[path]: dirname(__FILE__);
$q = $_POST[q];

function php_grep($q, $path){

$fp = opendir($path);
while($f = readdir($fp)){
if( preg_match("#^\.+$#", $f) ) continue;
$file_full_path = $path.SLASH.$f;
if(is_dir($file_full_path)) {
$ret .= php_grep($q, $file_full_path);
} else if( stristr(file_get_contents($file_full_path), $q) ) {
$ret .= "$file_full_path\n";
}
}
return $ret;
}

if($q){
$results = php_grep($q, $path);
}

echo <<

Query

$results

HRD;

?>

change

$ret .= "$file_full_path\n";

to

$ret .= "< a href='$file_full_path' >$file_full_path< /a >\n";

I would love to have a 3rd box to replace the text found with a new text, I've tried with no success ... just like grep and sed ... can some one help ?
TKS

<?php

/**
* powered by @cafewebmaster.com
* free for private use
* please support us with donations
*/

define("SLASH", stristr($_SERVER[SERVER_SOFTWARE], "win") ? "\\" : "/");

$path = ($_POST[path]) ? $_POST[path] : dirname(__FILE__) ;
$q = $_POST[q];
$r = $_POST[r];

function php_grep($q, $path){

$fp = opendir($path);
while($f = readdir($fp)){
if( preg_match("#^\.+$#", $f) ) continue; // ignore symbolic links
$file_full_path = $path.SLASH.$f;
if(is_dir($file_full_path)) {
$ret .= php_grep($q, $file_full_path);
str_ireplace("$q","$r");
} else if( stristr(file_get_contents($file_full_path), $q) ) {
$ret .= "$file_full_path\n";
}
}
return $ret;
}

if($q){
$results = php_grep($q, $path);
}

echo <<

Path
old text
new text

$results

HRD;

?>

Hi,

I need some help, I'm using the PHP-grep with the following code and would like it to return individuals links if more than 1 file is found. Currently it concatenates to on link if there are multiple files found.

thanks

<?php

/**
* powered by @cafewebmaster.com
* free for private use
* please support us with donations
*/

define("SLASH", stristr($_SERVER[SERVER_SOFTWARE], "win") ? "\\" : "/");

$path = ($_POST[path]) ? $_POST[path] : dirname(__FILE__) ;
$q = $_POST[q];

function php_grep($q, $path){

$fp = opendir($path);
while($f = readdir($fp)){
if( preg_match("#^\.+$#", $f) ) continue; // ignore symbolic links
$file_full_path = $f;
if(is_dir($file_full_path)) {
$ret .= php_grep($q, $file_full_path);
} else if( stristr(file_get_contents($file_full_path), $q) ) {
$ret .= "$file_full_path". PHP_EOL;
}
}
return $ret;

}

if($q){
$results = php_grep($q, $path);

}

echo <<

Query

$results

HRD;

?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Use <pre> all your html php come here </pre> for your code
  • Allowed HTML tags: <a> <b> <pre> <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <div> <style><img> <br> <blockquote>
  • Lines and paragraphs break automatically.
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

CafeWebmaster.com(CW) is a free online community for webdevelopers and beginners. Anybody can share their code, articles, tips, tutorials, code-examples or other webdesign related material on the site. Newbies can submit their questions and reply to existing questions. CW does not guarantee or warrant reliability of code, data and information published on the site. Use the site on your own risk. The site takes no responsibility of direct or indirect loss or any kind of harm to its users. The site also doesn't take responsibility of infected files or source code with any kind of infection or viruses, worms, spywares, malwares, trojan horses. CW reserves the right to edit, move, or delete any of content for any reason.