0

I have a string that looks like "/Images/Folder/1.jpeg" or "/Images/Folder/55.jpeg"

How do I parse this string so I can get the digit "1" or "55" for example into a string of its own?

The /Images/Folder/ and the ".jpeg" will be constant so I could use them as delimiters.

4
  • 1
    Regex is nice but really not needed for something so simple (in reply to someones deleted comment). php.net/manual/en/function.explode.php Commented Oct 28, 2015 at 23:38
  • @Jesse yes, sorry my bad. I totally forgot about explode. Commented Oct 28, 2015 at 23:40
  • The pathinfo() function exists specifically for breaking down a filepath like this: $digits = pathinfo("/Images/Folder/1.jpeg", PATHINFO_FILENAME); Commented Oct 28, 2015 at 23:41
  • $i=intval( basename( $imgpath ) ); ? Commented Oct 28, 2015 at 23:42

1 Answer 1

3

You can use this:

$s = "/Images/Folder/1.jpeg";
$temp = explode('/', $s);
$temp2 = explode('.', $temp[count($temp) - 1]);
echo $temp2[0];

Result:

1
Sign up to request clarification or add additional context in comments.

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.