Get two words from URL after a slash in PHP

放肆的年华 提交于 2019-12-02 18:26:07

问题


I need to get two words from an URL. So for example I have the following URL:

http://mydomain.com/alrajhi/invoice/108678645541

I need to get with PHP only "alrajhi"and the number "108678645541" nothing else.

Can you help me please?

Thank you so much!!


回答1:


$string = 'http://mydomain.com/alrajhi/invoice/108678645541';
$parse = parse_url($string);
$explode = explode('/', $parse['path']);

Now you have:

echo $explode[1]; // alrajhi
echo $explode[3]; // 108678645541



回答2:


Check out 'parse_url' (PHP manual), a function that divides your url into its components and saves that to an array.



来源:https://stackoverflow.com/questions/22210343/get-two-words-from-url-after-a-slash-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!