Skip to main content
added 1 characters in body
Source Link
KingCrunch
  • 130.8k
  • 21
  • 153
  • 174

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

The snippet from the question doesnt work, because its evaluated into (shortened)

(substr($rrr['url'],-4)=='.jpg') || '.png'

This works, but oviously it doesnt make much sense and is very probably not, what is expected.

Update: This solution seems much cleaner. It assumes, that $rrr['url'] is the only interesting here. See comments

switch (pathinfo($rrr['url'], PATHINFO_EXTENSION)):
  case 'jpg':
  case 'png':
  case 'gif':
  case 'tif':
  case 'tiff':
    do_something();
  break;
}

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

The snippet from the question doesnt work, because its evaluated into (shortened)

(substr($rrr['url'],-4)=='.jpg') || '.png'

This works, but oviously it doesnt make much sense and is very probably not, what is expected.

Update: This solution seems much cleaner. It assumes, that $rrr['url'] is the only interesting here. See comments

switch (pathinfo($rrr['url'], PATHINFO_EXTENSION):
  case 'jpg':
  case 'png':
  case 'gif':
  case 'tif':
  case 'tiff':
    do_something();
  break;
}

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

The snippet from the question doesnt work, because its evaluated into (shortened)

(substr($rrr['url'],-4)=='.jpg') || '.png'

This works, but oviously it doesnt make much sense and is very probably not, what is expected.

Update: This solution seems much cleaner. It assumes, that $rrr['url'] is the only interesting here. See comments

switch (pathinfo($rrr['url'], PATHINFO_EXTENSION)):
  case 'jpg':
  case 'png':
  case 'gif':
  case 'tif':
  case 'tiff':
    do_something();
  break;
}
added 257 characters in body; added 62 characters in body
Source Link
KingCrunch
  • 130.8k
  • 21
  • 153
  • 174

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

The snippet from the question doesnt work, because its evaluated into (shortened)

(substr($rrr['url'],-4)=='.jpg') || '.png'

This works, but oviously it doesnt make much sense and is very probably not, what is expected.

Update: This solution seems much cleaner. It assumes, that $rrr['url'] is the only interesting here. See comments

switch (pathinfo($rrr['url'], PATHINFO_EXTENSION):
  case 'jpg':
  case 'png':
  case 'gif':
  case 'tif':
  case 'tiff':
    do_something();
  break;
}

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

The snippet from the question doesnt work, because its evaluated into (shortened)

(substr($rrr['url'],-4)=='.jpg') || '.png'

This works, but oviously it doesnt make much sense and is very probably not, what is expected.

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

The snippet from the question doesnt work, because its evaluated into (shortened)

(substr($rrr['url'],-4)=='.jpg') || '.png'

This works, but oviously it doesnt make much sense and is very probably not, what is expected.

Update: This solution seems much cleaner. It assumes, that $rrr['url'] is the only interesting here. See comments

switch (pathinfo($rrr['url'], PATHINFO_EXTENSION):
  case 'jpg':
  case 'png':
  case 'gif':
  case 'tif':
  case 'tiff':
    do_something();
  break;
}
added 233 characters in body
Source Link
KingCrunch
  • 130.8k
  • 21
  • 153
  • 174

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

The snippet from the question doesnt work, because its evaluated into (shortened)

(substr($rrr['url'],-4)=='.jpg') || '.png'

This works, but oviously it doesnt make much sense and is very probably not, what is expected.

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

Something like this?

case in_array(substr($rrr['url'],-4), array('.jpg','.png','.gif','.tif')):
case in_array(substr($rrr['url'],-5), array('.tiff')):

Note, that I omit break; between the case-expression.

Also cool:

case in_array(pathinfo($rrr['url'], PATHINFO_EXTENSION), array('jpg','png','gif','tif', 'tiff')):

The snippet from the question doesnt work, because its evaluated into (shortened)

(substr($rrr['url'],-4)=='.jpg') || '.png'

This works, but oviously it doesnt make much sense and is very probably not, what is expected.

Source Link
KingCrunch
  • 130.8k
  • 21
  • 153
  • 174
Loading