Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-29 Thread Jochem Maas

James Ausmus schreef:

On Tue, Aug 26, 2008 at 10:08 AM, Ford, Mike [EMAIL PROTECTED] wrote:

On 26 August 2008 17:15, James Ausmus advised:


On Tue, Aug 26, 2008 at 8:57 AM, Ford, Mike
[EMAIL PROTECTED] wrote:

On 25 August 2008 00:54, Govinda advised:

snip


Personally, I might be tempted to do something like this:

  if (($pos = strrchr($file, '.'))!==FALSE):
 switch (strtolower(substr($file, $pos))):
case '.gif':
case '.png':
case '.jpg':
case '.jpeg':
   echo $file;
 endswitch;
  endif;

snip

Of course, this could be simplified *slightly* by actually taking
advantage of the loose typing of PHP - change the above if statement

to:

if (($pos = strpos($file, '.')))
{
$restOfAboveCodeHere;
}

This way, if the file is the '.' or '..' files, then you will get a 0
for the position of the '.', which will evaluate to FALSE. All other
files will return a non-zero position of the '.' char, which will
evaluate to TRUE. Also, I would believe (but have no evidence at all
of) that a forward-looking string position search will be very
slightly faster than a strrchr search - dunno for certain, and don't
care enough to code up a couple-line test, but just my gut... ;)

The problem with that is that a file called, say, site.logo.jpg will
fail the subsequent tests, since the substr() on the next line will
return '.logo.jpg'.  (And whilst it is vanishingly improbable, it is
_just_ possible for someone to supply a file called .gif ! ;)



Very true - shows what a couple seconds of thought prior to full
caffeine will give you. ;)

However, it still does illustrate a concept that is important - making
PHP's loose typing work *for* you, instead of fighting against it -
many of the posts here have approximately said DANGER! Loose typing
ahead!, which could tend to make a new PHP programmer only think of
the loose typing in a negative form - something to watch out for and
avoid. If, however, you internalize the implications of loose typing,
then you can actually make good use of it, instead of just guarding
against it like the plague. ;)


very good point.

indeed it should be noted loosetyping is a good thing, you just need
to understand how to use it diligently. anyone who thinks it's evil
can always f*** off to the java camp :-P



-James



Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus,
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php







--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-26 Thread Ford, Mike
On 25 August 2008 00:54, Govinda advised:


 
 
 if (stripos(strrev($file), gpj.) === 0) {
  echo $file;
 }
 
 note the ===, 3 equals signs here is very important! check the docs
 for why.
 
 == means 'equals', and === means 'is identical to'.
 Seems like they would do the same thing when comparing '0' to 'the
 position in the string where that substr is found'.  Why not?

They would -- but stripos will also return FALSE if there is no match,
and FALSE==0 too!

 or you could go a little more robust with regular expressions
 
 if (preg_match(#^.*\.(jpe?g|gif|png)$#i, $file) {
  echo $file; // any image file is echo'ed
 }
 ahhh reg expressions.  So looking forward to when I can see PHP
 properly/clearly enough to throw them in too!  (meanwhile I better get
 the basics first ;-)

Personally, I might be tempted to do something like this:

   if (($pos = strrchr($file, '.'))!==FALSE):
  switch (strtolower(substr($file, $pos))):
 case '.gif':
 case '.png':
 case '.jpg':
 case '.jpeg':
echo $file;
  endswitch;
   endif;

But then, I might go with the pattern match or the glob() solution, too!
;)

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-26 Thread James Ausmus
On Tue, Aug 26, 2008 at 8:57 AM, Ford, Mike [EMAIL PROTECTED] wrote:
 On 25 August 2008 00:54, Govinda advised:

snip

 Personally, I might be tempted to do something like this:

   if (($pos = strrchr($file, '.'))!==FALSE):
  switch (strtolower(substr($file, $pos))):
 case '.gif':
 case '.png':
 case '.jpg':
 case '.jpeg':
echo $file;
  endswitch;
   endif;

snip

Of course, this could be simplified *slightly* by actually taking
advantage of the loose typing of PHP - change the above if statement
to:

if (($pos = strpos($file, '.')))
{
$restOfAboveCodeHere;
}

This way, if the file is the '.' or '..' files, then you will get a 0
for the position of the '.', which will evaluate to FALSE. All other
files will return a non-zero position of the '.' char, which will
evaluate to TRUE. Also, I would believe (but have no evidence at all
of) that a forward-looking string position search will be very
slightly faster than a strrchr search - dunno for certain, and don't
care enough to code up a couple-line test, but just my gut... ;)

-James

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-26 Thread Lupus Michaelis

Ford, Mike a écrit :

 case '.gif':
 case '.png':
 case '.jpg':
 case '.jpeg':
echo $file;


  Be carefull. The « extension » is just a clue to know what filled the 
file. See http://fr3.php.net/manual/en/book.fileinfo.php.


--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-26 Thread Lupus Michaelis

Ford, Mike a écrit :

case '.gif':
 case '.png':
 case '.jpg':
 case '.jpeg':


  Be careful. The end of the filename is just a clue on what is filled 
the file. See http://fr3.php.net/manual/en/book.fileinfo.php for more 
acurate result.



--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-26 Thread Ford, Mike
On 26 August 2008 17:15, James Ausmus advised:

 On Tue, Aug 26, 2008 at 8:57 AM, Ford, Mike
 [EMAIL PROTECTED] wrote:
 On 25 August 2008 00:54, Govinda advised:
 
 snip
 
 Personally, I might be tempted to do something like this:
 
   if (($pos = strrchr($file, '.'))!==FALSE):
  switch (strtolower(substr($file, $pos))):
 case '.gif':
 case '.png':
 case '.jpg':
 case '.jpeg':
echo $file;
  endswitch;
   endif;
 
 snip
 
 Of course, this could be simplified *slightly* by actually taking
 advantage of the loose typing of PHP - change the above if statement
to:
 
 if (($pos = strpos($file, '.')))
 {
 $restOfAboveCodeHere;
 }
 
 This way, if the file is the '.' or '..' files, then you will get a 0
 for the position of the '.', which will evaluate to FALSE. All other
 files will return a non-zero position of the '.' char, which will
 evaluate to TRUE. Also, I would believe (but have no evidence at all
 of) that a forward-looking string position search will be very
 slightly faster than a strrchr search - dunno for certain, and don't
 care enough to code up a couple-line test, but just my gut... ;)

The problem with that is that a file called, say, site.logo.jpg will
fail the subsequent tests, since the substr() on the next line will
return '.logo.jpg'.  (And whilst it is vanishingly improbable, it is
_just_ possible for someone to supply a file called .gif ! ;)

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-26 Thread James Ausmus
On Tue, Aug 26, 2008 at 10:08 AM, Ford, Mike [EMAIL PROTECTED] wrote:
 On 26 August 2008 17:15, James Ausmus advised:

 On Tue, Aug 26, 2008 at 8:57 AM, Ford, Mike
 [EMAIL PROTECTED] wrote:
 On 25 August 2008 00:54, Govinda advised:

 snip

 Personally, I might be tempted to do something like this:

   if (($pos = strrchr($file, '.'))!==FALSE):
  switch (strtolower(substr($file, $pos))):
 case '.gif':
 case '.png':
 case '.jpg':
 case '.jpeg':
echo $file;
  endswitch;
   endif;

 snip

 Of course, this could be simplified *slightly* by actually taking
 advantage of the loose typing of PHP - change the above if statement
 to:

 if (($pos = strpos($file, '.')))
 {
 $restOfAboveCodeHere;
 }

 This way, if the file is the '.' or '..' files, then you will get a 0
 for the position of the '.', which will evaluate to FALSE. All other
 files will return a non-zero position of the '.' char, which will
 evaluate to TRUE. Also, I would believe (but have no evidence at all
 of) that a forward-looking string position search will be very
 slightly faster than a strrchr search - dunno for certain, and don't
 care enough to code up a couple-line test, but just my gut... ;)

 The problem with that is that a file called, say, site.logo.jpg will
 fail the subsequent tests, since the substr() on the next line will
 return '.logo.jpg'.  (And whilst it is vanishingly improbable, it is
 _just_ possible for someone to supply a file called .gif ! ;)


Very true - shows what a couple seconds of thought prior to full
caffeine will give you. ;)

However, it still does illustrate a concept that is important - making
PHP's loose typing work *for* you, instead of fighting against it -
many of the posts here have approximately said DANGER! Loose typing
ahead!, which could tend to make a new PHP programmer only think of
the loose typing in a negative form - something to watch out for and
avoid. If, however, you internalize the implications of loose typing,
then you can actually make good use of it, instead of just guarding
against it like the plague. ;)

-James


 Cheers!

 Mike

  --
 Mike Ford,  Electronic Information Developer,
 C507, Leeds Metropolitan University, Civic Quarter Campus,
 Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
 Email: [EMAIL PROTECTED]
 Tel: +44 113 812 4730


 To view the terms under which this email is distributed, please go to 
 http://disclaimer.leedsmet.ac.uk/email.htm

 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-25 Thread David Otton
2008/8/24 Govinda [EMAIL PROTECTED]:

 $ThisDir = getcwd()./thumbs;
 $DirHandle = opendir($ThisDir);
 if ($DirHandle = opendir($ThisDir)) {
   echo Directory handle: $DirHandle\n;
   echo Files:br /hr width=\25\%\ align=\left\ /;

 while ((false !== ($file = readdir($DirHandle)))  1) {
if (true == ($file=.jpg)) {
echo $filebr /;
}
}
closedir($DirHandle);
 }

 But instead of printing only the name of the file which is equal to
 .jpg, it seems to actually set the value of $file to .jpg on
 each iteration of the while loop, so what I get is a list of files all
 having the same name (.jpg) and their number is equal to the actual
 number of files in that dir (plus 2 - for the . and .. files).

 How to say, if the fileNAME is equal to..., or better yet, if the
 fileNAME ends with '.jpg'?

Hi, you've had a lot of responses to issues in your code snippet. I'm
just here to point out - for the sake of the archives, really - that
there are at least two more approaches you could take. PHP is one of
those languages where there's more than one way to do most things.

?php
$path = './thumbs/' . sql_regcase ( '*.jpg' );

foreach ( glob( $path ) as $filename )
{
echo {$filename}br/;
}

You can check the manual for full details, but briefly, sql_regcase()
returns a case-insensitive regular expression, and glob() returns an
array of filenames that match the path given to it (in this case
./thumbs/*.jpg).

?php
$dir = new DirectoryIterator( './thumbs/' );

foreach( $dir as $file )
{
if ( preg_match( /jpg$/i, $file-getFilename() ) )
{
echo $file-getFilename() . br/;
}
}

In this one, we're iterating over a DirectoryIterator object
(http://uk2.php.net/manual/en/class.directoryiterator.php) instead of
the output of glob(). RecursiveDirectoryIterator also exists, which
allows you to traverse an entire tree, rather than just one directory.

You've already been pointed to preg_match(), so I won't explain that one again.

-- 

http://www.otton.org/category/programming/php-tips-tricks/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-25 Thread Jochem Maas

Chris schreef:



if (stripos(strrev($file), gpj.) === 0) {
echo $file;   }

note the ===, 3 equals signs here is very important! check the docs 
for why.


== means 'equals', and === means 'is identical to'.
Seems like they would do the same thing when comparing '0' to 'the 
position in the string where that substr is found'.  Why not?


0 can mean false in php:


indeed, php is dynamically typed and happily auto-casts all of the place
without issue ... this can bite you in the ass if your not aware of how
php auto-casts various types, and which types have precendence.

the manual should help, additionally test your assumptions regularly on the 
cmdline
with snippets like:

php -r ' var_dump(( == false), (1 == 1), (two == 1), (two == false));'

using === o test equality force type to be checked as well as 'content' of
the given LH and RH expressions.


$found = 0;

if (!$found) {
  echo File not found;
}

If a substr comparison matches at char 0:

$string = '12345';
$pos = substr($string, '1');

then without the '===' it would give the wrong result as $pos would be 
converted to false in this example.





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-25 Thread David Otton
2008/8/25 David Otton [EMAIL PROTECTED]:

 You can check the manual for full details, but briefly, sql_regcase()
 returns a case-insensitive regular expression, and glob() returns an
 array of filenames that match the path given to it (in this case
 ./thumbs/*.jpg).

I should have mentioned that glob() accepts shell wildcard expansions,
not regular expressions. But in this case they're similar enough that
you can get away with a mix-and-match approach.

-- 

http://www.otton.org/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-25 Thread Philip Thompson

On Aug 24, 2008, at 6:54 PM, Govinda wrote:

Should I send replies to just the list?, or is the etiquette to  
reply-to-all?


You will get different opinions from different people on the list.  
IMO, Reply-All is really annoying. Since I'm on the list, there's no  
need to reply to me - I'll get the email via the list.


However, it is personal preference. I think the big deal is to *at  
least* reply to the list - that way we can all learn from what's being  
said. =D


~Philip


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-25 Thread tedd

At 7:53 AM -0500 8/25/08, Philip Thompson wrote:

On Aug 24, 2008, at 6:54 PM, Govinda wrote:


Should I send replies to just the list?, or is the etiquette to reply-to-all?


You will get different opinions from different people on the list. 
IMO, Reply-All is really annoying. Since I'm on the list, there's no 
need to reply to me - I'll get the email via the list.


However, it is personal preference. I think the big deal is to *at 
least* reply to the list - that way we can all learn from what's 
being said. =D


~Philip



I usually hit Reply All and then remove all email addresses except 
for php-general.


In addition, I also trim the replies down to what's important -- I 
hate long-ass emails.


In fact, it would be great if I could just see my emails without the 
32 lines of header fluff that accompanies each one.


I'm using Eudora for the Mac and the first 32 lines of all my emails 
are the header and if I click the Blah Blah button (that's supposed 
to show the header information), then I get another 25 lines of 
header. That's 57 lines in total to get to the contents of the email 
-- far more than what I need/want.


I've checked all the preference setting numerous time trying to cut 
down on the length of my emails but had no luck. I have to scroll 
every email to read -- that's a pain.


Cheers,

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-25 Thread Philip Thompson

On Aug 25, 2008, at 8:16 AM, tedd wrote:


At 7:53 AM -0500 8/25/08, Philip Thompson wrote:

On Aug 24, 2008, at 6:54 PM, Govinda wrote:

Should I send replies to just the list?, or is the etiquette to  
reply-to-all?


You will get different opinions from different people on the list.  
IMO, Reply-All is really annoying. Since I'm on the list, there's  
no need to reply to me - I'll get the email via the list.


However, it is personal preference. I think the big deal is to *at  
least* reply to the list - that way we can all learn from what's  
being said. =D


~Philip



I usually hit Reply All and then remove all email addresses except  
for php-general.


Exactly what I do!

In addition, I also trim the replies down to what's important -- I  
hate long-ass emails.


[Snip!]

I've checked all the preference setting numerous time trying to cut  
down on the length of my emails but had no luck. I have to scroll  
every email to read -- that's a pain.


Apple Mail. It's by far the best email app I've seen/used. =D You can  
hide/view headers as desired.


~Philip


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-25 Thread Wolf
!-- SNIP --
 I'm using Eudora for the Mac and the first 32 lines of all my emails 
 are the header and if I click the Blah Blah button (that's supposed 
 to show the header information), then I get another 25 lines of 
 header. That's 57 lines in total to get to the contents of the email 
 -- far more than what I need/want.

Really, they still make Eudora?  Or is this an old copy on the MacIntosh IIe 
that you are running.  ;)

Wolf

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-24 Thread Chris




But two of those entries are apparently named . and ...



Right. That's linux doing that, not php. If you jump into a ssh 
connection and do an


$ ls -la

you will see

. and .. at the top.

if ($filename == '.' || $filename == '..') {
  continue;
}


  I haven't yet found the 'string.ends_with'
function in the docs, so I am just seeing if I can (to learn step by 
step) instead  wrap that echo line with an if statement that says if 
the name of the file is equal to (.jpg), like so:


$ThisDir = getcwd()./thumbs;
$DirHandle = opendir($ThisDir);
if ($DirHandle = opendir($ThisDir)) {
   echo Directory handle: $DirHandle\n;
   echo Files:br /hr width=\25\%\ align=\left\ /;

while ((false !== ($file = readdir($DirHandle)))  1) {
if (true == ($file=.jpg)) {
echo $filebr /;
}
}
closedir($DirHandle);
}

But instead of printing only the name of the file which is equal to 
.jpg, it seems to actually set the value of $file to .jpg on 
each iteration of the while loop, so what I get is a list of files all 
having the same name (.jpg) and their number is equal to the 
actual number of files in that dir (plus 2 - for the . and .. files).


Because you have:

$file = 'xxx.jpg';

That is an assignment.

What you want is a comparison:

$file == 'xxx.jpg';

Note the double ='s.

http://www.php.net/manual/en/language.operators.php


In this case, I'd use the pathinfo function to break up the file/path:

http://www.php.net/manual/en/function.pathinfo.php


--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-24 Thread Jochem Maas

Govinda schreef:

Hi all :-)
It'll be fun to work here with you guys over the coming months. 


fun? work? you must be new :-)

I have 
been out of the coding loop for 7 years, and I am totally new to PHP, 
but I should catch up not-too-slowly as I used to code HTML, WebDNA, and 
a little Visual Basic too.  Kindly bear with me.


little bear or big bear?

okay enough jokes (but now you know the list flavor at least)



First Q:
This code does list the files in my dir just fine:

$ThisDir = getcwd()./thumbs;
$DirHandle = opendir($ThisDir);
if ($DirHandle = opendir($ThisDir)) {
   echo Directory handle: $DirHandle\n;
   echo Files:br /hr width=\25\%\ align=\left\ /;

while ((false !== ($file = readdir($DirHandle)))  1) {
echo $filebr /;
}
closedir($DirHandle);
}

But two of those entries are apparently named . and ...


they are quite common in most filesystem :-P

Feel free to enlighten me on that, but, always trying to be 


like John Lennon said ... by heck you gotta save yourself
(damn I said I'd stop with the jokes didn't I)


self-sufficient, I attempt to workaround by wrapping this line:
echo $filebr /;
with  an if statement that I want to only show the file if it ends with 
the extension .jpg.  I haven't yet found the 'string.ends_with' 
function in the docs, so I am just seeing if I can (to learn step by 
step) instead  wrap that echo line with an if statement that says if 
the name of the file is equal to (.jpg), like so:


$ThisDir = getcwd()./thumbs;


becareful with getcwd(), look into other methods of determining
paths, e.g. dirname(__FILE__).


$DirHandle = opendir($ThisDir);
if ($DirHandle = opendir($ThisDir)) {
   echo Directory handle: $DirHandle\n;
   echo Files:br /hr width=\25\%\ align=\left\ /;


save yourself a million slashes:

echo 'Files:br /hr width=25% align=left /';

double quotes interpolate variables, single quotes don't.



while ((false !== ($file = readdir($DirHandle)))  1) {
if (true == ($file=.jpg)) {
echo $filebr /;


this *could* be written as:

echo $file, 'br /';

just a thought.


}
}
closedir($DirHandle);
}

But instead of printing only the name of the file which is equal to 
.jpg, it seems to actually set the value of $file to .jpg on


use == to test equality, = is to set a variable.

each iteration of the while loop, so what I get is a list of files all 
having the same name (.jpg) and their number is equal to the 
actual number of files in that dir (plus 2 - for the . and .. files).


there is is_dir() to check if it's a dir. but that's not what you want here.

you could do something hackish like

if (stripos(strrev($file), gpj.) === 0) {
echo $file; 
}

note the ===, 3 equals signs here is very important! check the docs for why.

or you could go a little more robust with regular expressions

if (preg_match(#^.*\.(jpe?g|gif|png)$#i, $file) {
echo $file; // any image file is echo'ed
}

if (preg_match(#^.*\.jpe?g$#i, $file) {
echo $file; // any jpeg file is echo'ed
}



How to say, if the fileNAME is equal to..., or better yet, if the 
fileNAME ends with '.jpg'?


http://php.net/manual/en/ref.strings.php lists all the basic string funcs,
have fun with inconsistent argument order in some of those! after 7+ years
of php I still get the order wrong for some of them :-)


Thanks,
-Govinda




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-24 Thread Govinda
Should I send replies to just the list?, or is the etiquette to reply- 
to-all?



fun? work? you must be new :-)


new to PHP; could get boring after a long time with it, sure... but I  
have that 'coder's bug'...  i.e. once fluent, then creatively solving  
problems is fun!



okay enough jokes (but now you know the list flavor at least)
Thank God!  ..for lightness/humor.  :-P  ..esp. in these otherwise dry  
circles of coding!



becareful with getcwd(), look into other methods of determining
paths, e.g. dirname(__FILE__).
The page I am making needs to work in any old PHP-enabled dir we stick  
it in.  (It's only for internal html generation, for now.)


double quotes interpolate variables, single quotes don't.

this *could* be written as:

echo $file, 'br /';
use == to test equality, = is to set a variable.


all your time and precision will always be appreciated!



if (stripos(strrev($file), gpj.) === 0) {
echo $file; 
}

note the ===, 3 equals signs here is very important! check the docs  
for why.


== means 'equals', and === means 'is identical to'.
Seems like they would do the same thing when comparing '0' to 'the  
position in the string where that substr is found'.  Why not?



or you could go a little more robust with regular expressions

if (preg_match(#^.*\.(jpe?g|gif|png)$#i, $file) {
echo $file; // any image file is echo'ed
}
ahhh reg expressions.  So looking forward to when I can see PHP  
properly/clearly enough to throw them in too!  (meanwhile I better get  
the basics first ;-)


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] newbie Q: How to say, if the fileNAME is equal to..., or better yet, if the fileNAME ends with '.jpg'?

2008-08-24 Thread Chris



if (stripos(strrev($file), gpj.) === 0) {
echo $file;   
}


note the ===, 3 equals signs here is very important! check the docs 
for why.


== means 'equals', and === means 'is identical to'.
Seems like they would do the same thing when comparing '0' to 'the 
position in the string where that substr is found'.  Why not?


0 can mean false in php:

$found = 0;

if (!$found) {
  echo File not found;
}

If a substr comparison matches at char 0:

$string = '12345';
$pos = substr($string, '1');

then without the '===' it would give the wrong result as $pos would be 
converted to false in this example.


--
Postgresql  php tutorials
http://www.designmagick.com/


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php