Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.