PHP Explode ...?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • londres9b
    New Member
    • Apr 2010
    • 106

    PHP Explode ...?

    I know this:
    Code:
    <?php
    /**
    code owner: Rahul Sinha
    contact : rahul@zimaudio.com/rahulazm@gmail.com
    **/
    $str='http://www.mysite.com/directory/page.php';
    $arr = explode("com/",$str);
    echo $arr[1]; // prints directory/page.php
    
    ?>
    But what I want is to get directory/page (without .php)
    or http://www.mysite.com/directory/page

    How can I achieve this?
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    if you know the file extension, use basename()

    Comment

    • londres9b
      New Member
      • Apr 2010
      • 106

      #3
      Many Thanks!

      Comment

      • Kong Chun Ho
        New Member
        • Jul 2010
        • 34

        #4
        There is also another way if you want:
        Code:
        <?php 
        /** 
        code owner: Rahul Sinha 
        contact : rahul@zimaudio.com/rahulazm@gmail.com 
        **/ 
        $str='http://www.mysite.com/directory/page.php'; 
        $arr = explode("com/",$str); 
        $arr = explode(".", $arr[1]);
        echo $arr[0];  
        ?>

        Comment

        • londres9b
          New Member
          • Apr 2010
          • 106

          #5
          That's exactly what I want.
          Thank You.

          Comment

          Working...