473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

search text file

44
Hi everyone i want to search the text file,using pregmatch() but it seems like
it dose't serch.maybe my serching pattern is not right.look at the following code.

Myfile look like this
--------------------------------
file : (49/06/01) [2007] simon 13;
file : (68/05/01) [2007] John 17 ;

i want to serch [2007] simon 13 on the text file.
can anyone help me with pregmatch patterns.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $jaar = $_POST[year];
  3. $name = $_POST[name];
  4. $empno = $_POST[employeeno];
  5. $file =$q."Myfile.txt"; // q =path to myfile
  6. $toSearch = "[".$jaar."]"." ".$name." ".$empno;
  7. $lines = file($file); 
  8.  
  9. $count;
  10. $lineNumbers;
  11.  
  12. if ($lines)
  13.  
  14. {
  15.  
  16.    foreach($lines as $lineNumber) 
  17.  
  18.     { 
  19.     $lineNumbers++;
  20.  
  21.         $foundAMatch = preg_match("/$toSearch/i", $lineNumber, $matches, PREG_OFFSET_CAPTURE); 
  22.  
  23.         if ($foundAMatch > 0) 
  24.  
  25.             { 
  26.  
  27.                    $found = $matches[0][0]; 
  28.  
  29.                $count=$lineNumber;
  30.                         echo $lineNumber."<br />";
  31.  
  32.  
  33.             }         
  34.  
  35.         }    
  36.  
  37.         //$str_array = explode(" ",$count);
  38.  
  39.         //echo $str_array[0]."<br/>";
  40.  
  41.  
  42.  
  43.     }
  44.  
  45.     else
  46.  
  47.     {
  48.  
  49.         $line="no file/folder found";
  50.  
  51.         echo $line;
  52.  
  53.     }
  54. ?>
Aug 8 '08 #1
1 1717
Try this:

$toSearch = "\\[{$jaar}\\] {$name} {$empno}";
Aug 8 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Les Juby | last post by:
A year or two back I needed a search script to scan thru HTML files on a client site. Usual sorta thing. A quick search turned up a neat script that provided great search results. It was fast,...
3
by: jdworley | last post by:
Howdy! The search is a 1 GB+ file from a crash to be exact - had an e-mail correspondence (window) hopefully in it so I saved the file on reboot before windoze kicked in and want to open and...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
2
by: richardkreidl | last post by:
I want to be able to delete and search for elements in a XML file, I'm using the code below for adding elements which works great: Public Sub cmdAddElement_Click(ByVal sender As System.Object,...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
5
by: Mark | last post by:
Hi I have an application (in vb.NET 2005) which holds data in SQL Server and some of the SQL records are simply paths to related files. I would like to be able to do a text search on both the...
1
by: nganglove | last post by:
C++ string search -------------------------------------------------------------------------------- Hello, please can any one help me? I am given an assigment in C++ to read a text file and...
3
by: =?Utf-8?B?UGVycmlud29sZg==?= | last post by:
Not sure where to post this... Found some interesting behavior in Windows Search (Start =Search =All files and folders =search for "A word or phrase in the file:"). This applies to XP and maybe...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.