Re: string...
| From: | Michael Virnstein | Date: | Fri, 12 Apr 2002 11:53:15 +0000 |
| Subject: | Re: string... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-92748@lists.php.net to get a copy of this message | ||
beware if you're using preg_match instead.
regex using preg_match have to be enclosed by /
so the same with preg_match would look like:
preg_match("/^.*_[0-9]{4}\.jpg$/i", $file_name)
and using preg_match meens that / is a special character and has to be
backslashed if
wanted by it's meening. and there's nothing like preg_matchi to check
case-insensitive.
this has to be done using modifiers after the ending /. in the example above
it's i for case-insensitive.
"Michael Virnstein" <michael.virnstein@brodos.de> schrieb im Newsbeitrag
news:20020412114256.96992.qmail@pb1.pair.com...
> wrong again:
> eregi("^/*_[0-9]{4}\.jpg$", $file_name)
>
> now yo say, / at the beginning between 0 and unlimited times, the rest is
> ok.
>
> try this, i rechecked my second example and saw that i did a \. at the
> beginning. this was wrong,
> because it'll search for a dot at the beginning. simply forget about the
> backslash before the first dot.
> This should finally work:
> eregi("^.*_[0-9]{4}\.jpg$", $file_name)
>
> . is a special character and meens every character. so if you want . by
it's
> meening you have to
> backslash it: \.
> so what my ereg meens now, is the following:
> any character at the beginning between 0 and unlimited times, followed by
an
> _, followed
> by 4 characters between 0 and 9 followed by a dot, followed by jpg which
has
> to be at the end of the string.
>
> Michael
>
> "Jas" <jlgerfen@hotmail.com> schrieb im Newsbeitrag
> news:20020411174558.72214.qmail@pb1.pair.com...
> > Ok, I have tried all 3 examples and even tried a few variations that you
> > have given me and so far nothing is getting displayed, is there a way to
> > check for errors? here is the code I am working with:
> >
> > // second selection for main image on main page
> > $dir_name = "/path/to/images/directory/";
> > $dir = opendir($dir_name);
> > $file_lost .= "<p><FORM METHOD=\"post\"
> > ACTION=\"done.php3\"
> > NAME=\"images\">
> > <SELECT NAME=\"images\">";
> > while ($file_names = readdir($dir)) {
> > if ($file_names != "." && $file_names !=".." &&
> > eregi("^/*_[0-9]{4}\.jpg$", $file_name)) {
> > $file_lost .= "<OPTION VALUE=\"$file_names\"
> > NAME=\"$file_names\">$file_names</OPTION>";
> > }
> > }
> > $file_lost .= "</SELECT><br><br><INPUT
> > TYPE=\"submit\" NAME=\"submit\"
> > VALUE=\"select\"></FORM></p>";
> > closedir($dir);
> >
> >
> > "Michael Virnstein" <michael.virnstein@brodos.de> wrote in message
> > news:20020411162144.73879.qmail@pb1.pair.com...
> > > and i'd suggest using eregi instead, because then also .Jpg or .JPG
will
> > be
> > > found.
> > >
> > > "Michael Virnstein" <michael.virnstein@brodos.de> schrieb im
Newsbeitrag
> > > news:20020411100433.83674.qmail@pb1.pair.com...
> > > > see what's wrong here:
> > > > ereg('(^[0-1231]$).jpg$',$file_name)
> > > >
> > > > [] meens a group of characters, so in your case
> > > > 0,1,2 and 3 are valid characters. you haven't defined any
> > > > modifer like ?,*,+ or{}, so one of this characters has to
> > > > be found exactly one time. you're using ^ outside the [] so it meens
> the
> > > > beginning of the string.
> > > > in your case none of these characters inside the [] can be found at
> the
> > > > beginning of the string.
> > > > then you use $ after the []. $ meens the end of the string. none of
> the
> > > > characters in the [] matches at the end of the string.
> > > > so this would be right:
> > > >
> > > > ereg('_[0-9]{4}\.jpg$', $file_name);
> > > >
> > > > so this meens:
> > > > the beginning of the string doesn't matter, because we have not
> > specified
> > > ^
> > > > at the beginning.
> > > > there has to be an underscore, followed by 4 characters between 0
and
> 9,
> > > > followed by an dot,
> > > > followed by j, followd by p, followed by g. g has to be at the end
of
> > the
> > > > string, because of the $.
> > > > or you can use:
> > > > ereg('^\.*_[0-9]{4}\.jpg$', $file_name);
> > > >
> > > > this will meen :
> > > > any characters at the beginning between 0 and unlimited times, then
> > > followed
> > > > by an underscore,
> > > > followed by 4 characters between 0 and 9, followed by a dot,
followed
> by
> > > > jpg. same as above
> > > > though. But the * is a real performance eater so it could be
slightly
> > > faster
> > > > if you're using the first example.
> > > >
> > > >
> > > >
> > > > "Jas" <jlgerfen@hotmail.com> schrieb im Newsbeitrag
> > > > news:20020410222934.89594.qmail@pb1.pair.com...
> > > > > I hate to say it but that didn't work, I have been trying
different
> > > > > variations of the same ereg('_(^90-9{4}$).jpg$',$file_names) and
> > nothing
> > > > > seems to work for me, I have also been looking at the ereg and
> > preg_ereg
> > > > > functions but they don't seem to make sense to me, here is the
code
> as
> > a
> > > > > whole if this helps:
> > > > > // query directory and place results in select box
> > > > > $dir_name = "/path/to/images/directory/on/server/"; // path to
> > directory
> > > > on
> > > > > server
> > > > > $dir = opendir($dir_name); // open the directory in question
> > > > > $file_lost .= "<p><FORM METHOD=\"post\"
> > > > > ACTION=\"done.php3\"
> > > > NAME=\"ad01\">
> > > > > <SELECT NAME=\"image_path\">";
> > > > > while ($file_names = readdir($dir)) {
> > > > > if ($file_names != "." && $file_names !=".."
> > > > > &&
> > > > ereg('_(^[0-9]{4}.jpg$)',
> > > > > $file_names)) // filter my contents
> > > > > {
> > > > > $file_lost .= "<OPTION VALUE=\"$file_names\"
> > > > > NAME=\"$file_names\">$file_names</OPTION>";
> > > > > }
> > > > > }
> > > > > $file_lost .= "</SELECT><br><br><INPUT
> > > > > TYPE=\"submit\"
> > NAME=\"submit\"
> > > > > VALUE=\"select\"></FORM></p>";
> > > > > closedir($dir);
> > > > > What I am trying to accomplish is to list the contents of a
> directory
> > in
> > > > > select box but I want to filter out any files that dont meet this
> > > criteria
> > > > > *_4444.jpg and nothing is working for me, any help or good
tutorials
> > on
> > > > > strings would be great.
> > > > > Jas
> > > > > "Erik Price" <pricee@hhbrown.com> wrote in message
> > > > >
> > > > > news:3484EF79-4CD0-11D6-BC9F-0050E4857868@hhbrown.com...
> > > > > >
> > > > > > On Thursday, April 11, 2002, at 05:59 AM, jas wrote:
> > > > > >
> > > > > > > Is this a correct string to show only files that look like so:
> > > > > > > *_2222.jpg
> > > > > > > if ($file_names != "." && $file_names
> > > > > > > !=".." &&
> > > > > > > ereg('(^[0-1231]$).jpg$',$file_name))
> > > > > > > Any help would be great.
> > > > > >
> > > > > > preg_match(/^_[0-9]{4,4}\.jpg$/, $file_name) should match any
> string
> > > > > > that starts with an underscore, is followed by exactly four
> digits,
> > > and
> > > > > > then a ".jpg". It will not match anything but this exact
string.
> > > > > >
> > > > > >
> > > > > > Erik
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > > > ----
> > > > > >
> > > > > > Erik Price
> > > > > > Web Developer Temp
> > > > > > Media Lab, H.H. Brown
> > > > > > pricee@hhbrown.com
> > > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
> >
> >
>
>