Re: preg_match

From: Date: Fri, 19 Aug 2005 03:43:01 +0000
Subject: Re: preg_match
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-220912@lists.php.net to get a copy of this message
On Thu, August 18, 2005 2:50 pm, Jon wrote: > preg_match_all("/Charges \s\s+ $total x (.+) /siU", $single, > $from_invoice); I would recommend using \\s instead of \s -- While \s doesn't have any meaning in PHP strings, so PHP just figures you must have meant \\s > The text has "Charges" then a variable amount of spaces a previously > picked > decimal number" x " (and the data I want)" " > > is this correct or am I missing something? It seems to work sometimes > and > not others and I have not quite figured out what makes it fail. > > The error I get is > Warning: preg_match_all(): unknown modifier '#' in "file" Does $single have a "#" character in it by any chance??? Ooooh. Or does $total sometimes have "/#" in it? Imagine that $total has "#/#" in it. Then your PRCE string turns into: "/Charges \s\s+ #/# x (.+) /siU" v--------^ Preg "sees" this / to end the search string, and then it sees a # after that, and thinks you are trying to use # the way you are using "siU" at the end. Only # ain't a valid character in that location. -- Like Music? http://l-i-e.com/artists.htm

« previous php.general (#220912) next »