NYCPHP Meetup

NYPHP.org

[nycphp-talk] Help with regex

Malcolm, Gary gmalcolm at professionalcredit.com
Fri May 16 16:58:04 EDT 2003


the error sounds like a file translation problem...

this may be crazy but erase and replace all the whitespace on line 37...

gary

> -----Original Message-----
> From: Nestor Florez [mailto:nestorflorez at earthlink.net]
> Sent: Friday, 16 May, 2003 1:55 PM
> To: NYPHP Talk
> Subject: Re: [nycphp-talk] Help with regex
> 
> 
> Dan et all,
> 
> Thanks for your help, I was able to do what I wanted 
> Using the following regex
>  $_ =~ s/.*[^>]+>(.*[^<])<\\/td>/\\1/gi;
> 
> I decide to use perl instead PHP because it was a lot easier 
> reading the files in perl with the "while(<FILE>)", but I 
> prefer PHP for creating web pages.
> When I tried using php
> -----------------------
> 33 $content = file($myfile);                #readfile into array
> 34 foreach($content as $line_num => $line) 
> 35 {
> 36   $a = "/.*[^>]+>(.*[^<])<\\/td>/\\1/";    #reg expression
> 37   $line = preg_replace($a, '$1', $line); #replace
> 38 }
> ------------------------------
> I still get an error:
> Warning: Unknown modifier '' in c:\\program files\\apache 
> group\\apache\\htdocs\\php\\readphone.php on line 37
> 
> My problem is solved, but I wish what was causing the error message.
> 
> Thnaks again to all,
> 
> Nestor :-)
> 
> 
> Is ther an easy way to read a file in PHP like there is in perl
> -------Original Message-------
> From: Analysis & Solutions <danielc at analysisandsolutions.com>
> Sent: 05/16/03 09:28 AM
> To: NYPHP Talk <talk at nyphp.org>
> Subject: Re: [nycphp-talk] Help with regex
> 
> > 
> > Hi Nestor:
> 
> On Fri, May 16, 2003 at 11:27:23AM -0400, Nestor Florez wrote:
> 
> >    <td width="49">205</td>
> >
> >  $line = ereg_replace(".*>", "", $line);
> 
> As you probably realized, this is too greedy.  The reason is 
> because ".*"
> is matching ANY character, including ">" so it goes through 
> the whole line
> until it gets to the final ">"  This can be tweaked a tad so all
> characters except ">" are 
> 
>     $line = ereg_replace('^[^>]+>', '', $line);
> 
> Also notice the anchoring of the expression to the start of 
> the line to 
> avoid the expression repeating it's actions on subsequent 
> >'s, and the use 
> 
> of single quotes since no variables are in the expressions.
> 
> 
> > $line = ereg_replace(".*?>", "", $line);
> 
> You're on the right track, but "?" is for preg expressions.  
> So, another 
> option is converting it to a preg function:
> 
>    $line = preg_replace('/^.*?>/', '', $line);
> 
> Enjoy,
> 
> --Dan
> 
> -- 
>      FREE scripts that make web and database programming easier
>            <a target=_blank
> href="http://www.analysisandsolutions.com/software/">http://ww
> w.analysisandsolutions.com/software/</a>
>  T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
>  4015 7th Ave #4AJ, Brooklyn NY    v: 718-854-0335   f: 718-854-0409
> 
> 
> --- Unsubscribe at <a target=_blank
> href="http://nyphp.org/list/">http://nyphp.org/list/</a> ---
> 
> 
> >
> 
> 
> 
> --- Unsubscribe at http://nyphp.org/list/ ---
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20030516/f3519bff/attachment.html>


More information about the talk mailing list