Get two words from URL after a slash in PHP

前端 未结 2 832
予麋鹿
予麋鹿 2021-01-29 01:40

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 \"alra

相关标签:
2条回答
  • 2021-01-29 02:01
    $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
    
    0 讨论(0)
  • 2021-01-29 02:06

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

    0 讨论(0)
提交回复
热议问题