Get part of url in php

前端 未结 1 922
南旧
南旧 2021-01-29 07:42

I want to get a part of this url using php, what will be best approach

example url:

http://www.domain.com/44-Paris/blogs-for-travel/tour1.html

相关标签:
1条回答
  • 2021-01-29 08:39

    use parse_url

    <?php
        $url = 'http://www.domain.com/44-Paris/blogs-for-travel/tour1.html';
    
        $parse = parse_url($url);
        $path = explode('/', $parse['path']);
    
        echo $parse['scheme']."://".$parse['host']."/".$path[1]."/";
    ?>
    
    0 讨论(0)
提交回复
热议问题