1

I want to assign values of pathinfo function to variables like so:

list($dirname, $basename, $extension, $filename) = pathinfo($path_image);
echo $dirname.$basename.$extension.$filename;

However there is no output.

But if I run only:

print_r(pathinfo($path_image));

I get output like so:

Array ( [dirname] => http://blah.com/images [basename] => image123.jpg [extension] => jpg [filename] => image123) 
2
  • 2
    Comment number 2 here: php.net/manual/en/function.pathinfo.php Commented Sep 21, 2013 at 4:10
  • Put error_reporting(E_ALL); ini_set('display_errors', 1); at the top of your script and let us know what errors are you seeing now. Commented Sep 21, 2013 at 4:11

3 Answers 3

5
  1. list() is not a function, it is a language construction.
  2. It does not work with associative arrays. It works with indexed ones.

From php.net:

this is not really a function, but a language construct


list() only works on numerical arrays and assumes the numerical indices start at 0.


To fix that, you may try to ommit result array keys by array_values(), as mentiononed in answer of @anupam:

<?php
$values = array_values(pathinfo($path_image));
list($dirname, $basename, $extension, $filename) = $values;
?>
Sign up to request clarification or add additional context in comments.

Comments

2

pathinfo() returns an associative array. So, your code should work as follows:

list($dirname, $basename, $extension, $filename) = array_values(pathinfo($path_image));

Comments

2

Work:

list($dirname, $basename, $extension, $filename) = array_values(pathinfo($wallpaper_image));
echo $dirname.$basename.$extension.$filename;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.