Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Refine array with Explode or with other function

General discussions related to php

Moderators: macek, egami, gesf

Refine array with Explode or with other function

Postby Enragedash » Thu Jul 12, 2012 4:01 am

Purpose of the script is to list down all the files and folder in the directory.
But I want extract images files i.e .png, .gif, .jpg etc.

What should I do ? :help:


<?php
$adr=$_SERVER['DOCUMENT_ROOT'];

$files=scandir($adr);

$newlist=array($files);
$trims=array_slice($files,2);
asort($trims);

foreach($trims as $trim)
{

echo "<span class='link'> <a href='$trim' target='_relative'>$trim<br /></a>";

}

?>
Enragedash
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Jul 12, 2012 3:07 am

Re: Refine array with Explode or with other function

Postby johnj » Thu Jul 12, 2012 4:40 am

use regular expressions or substring functions to check if there are image files.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: Refine array with Explode or with other function

Postby Enragedash » Thu Jul 12, 2012 4:55 am

johnj wrote:use regular expressions or substring functions to check if there are image files.

how come substring can help ?
I guess with the substring function I can only set or end up string at desired value.

like
echo substr("Hello world!",6);
output
world!
Enragedash
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Jul 12, 2012 3:07 am

Re: Refine array with Explode or with other function

Postby Enragedash » Fri Jul 13, 2012 12:27 am

Thankx johnj. Anyways my problem is solved.

Substring=substr() wasn't the solution
I did it with stringposition=strpos()
Enragedash
New php-forum User
New php-forum User
 
Posts: 3
Joined: Thu Jul 12, 2012 3:07 am


Return to PHP General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

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