Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4077776
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:35:32+00:00 2026-05-20T17:35:32+00:00

I was using the strrchr PHP function with substr and strrpos to find the

  • 0

I was using the strrchr PHP function with substr and strrpos to find the file name in a string with the full path like:

/images/onepiece.jpg returns
onepiece.jpg

but now I need to a function to find not the last “/” but the one next to the last:
/images/anime/onepiece.jpg returning anime/onepiece.jpg or /anime/onepiece.jpg
And as strrchr – 1 doesn’t work, hehehe :), how can I achieve that?

[SOLVED]
Using PHP pathinfo() as @middaparka and @Shakti Singh said, I’ve change the way I get the image string from the MySQL database. Now it can have subfolders, as was my initial intention.

<?php
/*
 * pathinfo() parameters:
 * PATHINFO_DIRNAME = 1
 * PATHINFO_BASENAME = 2
 * PATHINFO_EXTENSION = 4
 * PATHINFO_FILENAME = 8
 * */
    $slash = '/';
    $mainpath = 'store/image/';
    $thumbspath = 'cache/';
    $path = $imgsrow->photo; //gets the string containing the partial path and the name of the file from the database
    $dirname = pathinfo($path, 1); //gets the partial directory string
    $basename = pathinfo($path, 2); //gets the name of the file with the extension
    $extension = pathinfo($path, 4); //gets the extension of the file
    $filename = pathinfo($path, 8); //gets the name of the file
    $dims = '-100x100.'; //string of size of the file to append to the file name
    $image = $mainpath . $path; //mainpath + path is the full string for the original/full size file
    $thumbs = $mainpath . $thumbspath . $dirname . $slash . $filename . $dims . $extension; //string to point to the thumb image generated from the full size file
?>
    <img src="<?= $thumbs; ?>" width="100" height="100" alt="<?= $row->description; ?>" />
    <br />
    <img src="<?= $image; ?>" width="500" height="500" alt="<?= $row->description; ?>" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:35:33+00:00Added an answer on May 20, 2026 at 5:35 pm

    To be honest, it would be a lot easier to use the pathinfo or dirname functions to decompose directory paths.

    For example:

    $filename = pathinfo('/images/onepiece.jpg', PATHINFO_BASENAME);
    $directory = dirname('/images/onepiece.jpg');
    

    You may have to use a mix of these to obtain what you’re after but they will at least be OS “safe” (i.e.: will handle both Linux/Linux and Windows path styles).

    In terms of the specific problem you have, you should be able to use the following cross-platform solution to get what you need:

    <?php
        $sourcePath = '/images/anime/onepiece.jpg';
    
        $filename = pathinfo($sourcePath, PATHINFO_BASENAME);
        $directories = explode(DIRECTORY_SEPARATOR, pathinfo($sourcePath, PATHINFO_DIRNAME));
    
        echo $directories[count($directories) -1] . DIRECTORY_SEPARATOR . $filename;
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know you can find the first and last occurrence in a string using
Using tanzaku in wordpress and get this error Warning: split() [function.split]: REG_EMPTY in /public/wp-content/themes/tanzaku/functions.php
I'm using the script from jquery file upload and modifying the create_scaled_image function to
I'm using some PHP code from jquery file upload and I'm trying to rotate
I have a question about the images displaying using a function getImage_w($image,$dst_w), which takes
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using import datetime in python, is it possible to take a formatted time/date string
Using ASIHTTPRequest, I downloaded a zip file containing a folder with several audio files.
I need to extract the name of the direct sub directory from a full
Using linq2sql I'm trying to take the string in txtOilChange and update the oilChange

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.