Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

How to not include jpgs ending _w.jpg in array

images php coding issues or problems here.

Moderators: macek, egami, gesf

How to not include jpgs ending _w.jpg in array

Postby DaveHenniker » Tue Aug 09, 2011 3:48 am

I'm successfully using Triptracker's PHP for slideshows such as http://www.henniker.org.uk/html/SampleSlideshow.php. To use an existing folder I have to move co-existing thumbnails to another folder otherwise it shows them too.

My thumbnails are named the same as their full size image but with _w.jpg at the end and I'd like to test for this so as to NOT include the thumbnails in the array.

The loop which creates the array:
<?php

require "../Scripts/common.php";
$images = getImagesInPath("../images/places/local_a/ed_sth/steeple");

foreach ($images as $image)
{
echo "slideshow.add('$image');\n";
}

?>

I can't seem to get hep from the How To page http://slideshow.triptracker.net/howto.html

Grateful thanks for any help
DaveHenniker
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Aug 09, 2011 3:27 am

Re: How to not include jpgs ending _w.jpg in array

Postby NigelRen » Tue Aug 09, 2011 4:16 am

You can easily check if a string ends with a particular value - use substr (http://php.net/manual/en/function.substr.php ) passing a negative value for the start position.

So in your case if you say...
Code: Select all
if ( substr($image,-6) != "_w.jpg" ) {
    echo "slideshow.add('$image');\n";
}


( Although I haven't tried it - so I can't guarantee it is accurate )
NigelRen
php-forum Active User
php-forum Active User
 
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: How to not include jpgs ending _w.jpg in array

Postby DaveHenniker » Tue Aug 09, 2011 4:43 am

Thank you. That worked fine. :D
DaveHenniker
New php-forum User
New php-forum User
 
Posts: 2
Joined: Tue Aug 09, 2011 3:27 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron