new_to_php Posted June 14, 2007 Share Posted June 14, 2007 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 .. Quote Link to comment https://forums.phpfreaks.com/topic/55557-regarding-php-search/ Share on other sites More sharing options...
calabiyau Posted June 14, 2007 Share Posted June 14, 2007 I think strip_tags will get rid of most of the unwanted html tags. Run it on $data right after your first line of code. Quote Link to comment https://forums.phpfreaks.com/topic/55557-regarding-php-search/#findComment-274993 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.