$path = parse_url($post->guid, PHP_URL_PATH);
echo "<pre>";
print_r($path);
echo "<br>";
here i get
/wp-content/uploads/2014/01/kl-2-256.png
/wp-content/uploads/2014/04/bg-eBook.pdf
here i want to remove /wp-conent/uploads from these paths and extract only year month and image name
i tried with
$segments = explode('/', rtrim($path, '/'));
but not working properly every time
is there any proper and best solution?
Would something like this work for you?
Use the
list()
construct to map the three data you need. The code is exploding the path by/
and then looks from behind and passes those values to your mapped variables oflist
.You can then print
$year,$month and $image
separately.