Search code examples
phpstring-parsing

Parsing a string to another string in PHP


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.


Solution

  • You can use this:

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

    Result:

    1