Saturday, February 18, 2023
HomeWordPress Developmentphp - Get the dynamic quantity after the final "/" of exterior...

php – Get the dynamic quantity after the final “/” of exterior url


There are lots of methods to do that, the best one-liner could be to make use of explode:

echo explode("/occasions/", $url)[1];

Or if one thing might come after ‘occasions/xxxxxx’:

$url = "https://knowledge.aboss.com/v1/company/1001/101010/occasions/1524447/different/123456";
echo explode("/", explode("/occasions/", $url)[1])[0]; // 1524447

You can even use a regex with preg_match:

$url = "https://knowledge.aboss.com/v1/company/1001/101010/occasions/1524447/different/123456";
$matches = [];
preg_match("~/occasions/(d+)~", $url, $matches); // captures digits after "/occasions/"
echo($matches[1]); // 1524447

Sandbox

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments