RE: Re: Spaces Not Detected from Regular Expression preg_match

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> To: php-general@xxxxxxxxxxxxx
> Date: Wed, 25 Feb 2009 14:42:36 -0600
> From: nospam@xxxxxxxxxxxxx
> Subject:  Re: Spaces Not Detected from Regular Expression preg_match
> 
> Shawn McKenzie wrote:
> > Shawn McKenzie wrote:
> >> Alice Wei wrote:
> >>> Hi, 
> >>>
> >>>   I have a code as in the following:
> >>>
> >>> <?php
> >>>
> >>>     $file = "test.txt";
> >>>     $fp = fopen($file, "r");
> >>>
> >>>    while(!feof($fp)) {
> >>>    $data = fgets($fp, 1024);
> >>>    
> >>>    if ((preg_match("/0/",$data)) || 
> >>>       (preg_match("/\"\s\"/",$data)) || 
> >>>       (preg_match("/\"\s\"/",$data))) {
> >>>          //Don't do a thing
> >>>    }
> >>>  
> >>> } 
> >>>     fclose($fp);
> >>>
> >>> ?>
> >>>
> >>>
> >>> This is the input file:
> >>>
> >>> 1
> >>> 23kd
> >>> 3dkd2
> >>> " "
> >>> 4
> >>> 5
> >>> 6
> >>>
> >>> For the output, I get nothing running it from the command prompt, but I would like to have " " in the output, 
> >>> could anyone please give me some guides on what I have done wrong in my regular expression?
> >>>
> >>> Thanks for your help.
> >>>
> >>> Alice
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> _________________________________________________________________
> >>> Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today!
> >>> http://get.live.com/toolbar/overview
> >> Ummm...  #1 you haven't "output" anything in your code.  Your code says,
> >> if " " is found in $data, then "Don't do a thing".
> >>
> >>
> >>
> > 
> > So if your wanting to see if there is a match in the line and return the
> > match (which in this example seems pointless because you know that you
> > are matching ""), then something like this:
> > 
> > if (preg_match("/0/",$data, $matches) ||
> >     preg_match("/\"\s\"/",$data, $matches))
> > {
> > 	print_r($matches);
> > }
> > 
> > BTW, the second and third conditions in your if appeared to be the same,
> > also \s matches whitespace, spaces, tabs, returns, etc...
> > 
> 
> I'll wait for a reply with more information as the more I look at your
> code it seems your off on a strange track.  I don't know the variability
> of your input data, but if you had a line 0 " " then the first
> preg_match would match the 0 and not the " ".  Maybe that's what you
> want, dunno...

Thanks, but I found that using line numbers of each and its remainder by a certain number works etter than using regular expressions here, since there is a lot of variability in the data from line to line.

Alice

> -- 
> Thanks!
> -Shawn
> http://www.spidean.com
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

_________________________________________________________________
Express yourself with gadgets on Windows Live Spaces
http://discoverspaces.live.com?source=hmtag1&loc=us

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux