Re: String?
| From: | Michael Virnstein | Date: | Thu, 11 Apr 2002 16:21:43 +0000 |
| Subject: | Re: String? | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-92606@lists.php.net to get a copy of this message | ||
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
> > >
> >
> >
>
>