Jump to content

Regarding PHP search


new_to_php

Recommended Posts

Hi ,

I have written following code to search in my internal website.

I am going through every directory and files in that directory , to search for a

particular keyword(search string).If I found that keyword I store that file name in an array.

$data=fread(fopen("$dir/$file","r"),filesize("$dir/$file"));
if(eregi("$keyword",$data))
{
  $array[]="$dir/$file";
  $startPosition = strpos($data,$keyword);
  $startPosition -= 40;
  if ($startPosition < 0) {
    $startPosition = 0;
  }
  $context = substr($data,$startPosition,80);
echo "context: $context";
print '<pre>';	

 

My intention is to store some text around the keyword inorder to

display it in result (40 chars before and 40 chars after keyword).

My problem is :

 

If a file is like this :

<html>
<head>
<title>Sample File</title>
</head>
<body>
This is a sample HTML file to test PHP search functionality
</body>
</html>

 

1. If I search for keyword "sample" in output(echo "$context")

  it is showing HTML tags also.

  means  <body>  This is a sample HTML file to test PHP search functionality

            </body>

  like that. In output result I dont want those tags.

  How to remove those tags.

2. If I find search string in a file , I want to capture that file title.

  How it can be done ???

  ( In above case  <title>Sample File</title> , I want co capture "sample File" )

 

Thank you ..

Link to comment
https://forums.phpfreaks.com/topic/55557-regarding-php-search/
Share on other sites

Archived

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

×
×
  • Create New...

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.