Showing posts with label How to find keyword in Whole site PHP. Show all posts
Showing posts with label How to find keyword in Whole site PHP. Show all posts

Friday 17 October 2014

How to Find String/keyword in Whole site PHP using unix commands



How to Find String/keyword in Whole site PHP using unix commands

Today i will show you how to find the strings/keywords in to your whole site or files in PHP. Its very hard to search keyword on live server sites so here i have make small script.

Make a file named search.php and copy below content and paste into search.php then put search.php file into your root directory. You can use this script in PHP Framework also. Like Magento, Wordpress, Opencart...

Note : Below coding only use for Linux server users.

<?php
ini_set('max_execution_time', 3600);
ini_set("memory_limit","256M");

$string = $_GET['string'];
if(trim($string) != '')
{
$script = "grep -n -r '$string' ".dirname(__FILE__);

$results = exec($script,$result);
if($results) {
echo "Search Result :";
echo '<pre>';
foreach ($result as $_result) {
echo $_result."<br/>";
}
echo '</pre>';
}
else {
echo "Search Completed, No results found.\n";
}
}
else {
echo "No String Found";
}

?>

Now you will need to execute the script from browser this way: http://yoursite.com/search.php?string=keyword