PHP link

Hi just wondering what i can do to change the output of the path for example…
$files = glob(“images/.”); for ($i=1; $i<count($files); $i++) {
$num = $files[$i]; print $num."
"; echo ‘random image’."


What it does is outputs every image which is in a folder, it also outputs the file name of each image. but … the image file names always say like /images/image001.jpg although i just want it to say… image001.jpg.


Though there are easier methods of accomplishing your task, to do it with the same code, you need only start the count at the 9-th character rather than the first character. Example

Rather than … ($i=1; $i<count($files);

do …($i=9; $i<count($files);

This would start the draw from the 9-th character of $files rather than including the first seven characters which are “\images”

Hope this helps.

[php]$files = glob(“images/.”); for ($i=1; $i<count($files); $i++)
{ $num = $files[$i];
print $num."
echo ‘random image’."



When i change the [php]r ($i=1; $i<count($files); $i++) [/php]
It changes which files to display, it only displays the files from the 9th on…

I think i need to edit something in
[php]$files = glob(“images/.”); [/php]
but what can i put in there?

actually it will be in this part as this is displaying the variable.

[php]echo 'random image[/php]

My bad. I did not fully review your purpose for the loop.

Ok. Here is your proper solution:

First get the length of your string…


Next subtract 8 (the number of characters in “/images/” from the length of your $numb …

Now Collect the remaining string by picking up the characters from a reverse stand point …


Here is an example of how this function.

substr("\images\myfilename", -10) returns “myfilename” … ten characters counting from the end of the string.

Going from the other direction, you could also use…

This would begin at position 10 in $numb and collect 10 characters.

The actual syn is like this:

string substr ( string $string , int $start [, int $length ] )

Sponsor our Newsletter | Privacy Policy | Terms of Service