Skip to main content
improved formatting
Source Link
palacsint
  • 29.9k
  • 9
  • 81
  • 156

URL Segment Classsegment class

In urls above:
$url->segment(1) : class
$url->segment(2) : method

  • $url->segment(1) : class
  • $url->segment(2) : method

If argument null, it will return the last segment:
$url->segment() : other

  • $url->segment() : other

I need suggestions for improvement this class, here is the code:

URL Segment Class

In urls above:
$url->segment(1) : class
$url->segment(2) : method

If argument null, it will return last segment:
$url->segment() : other

I need suggestions for improvement this class, here the code:

URL segment class

In urls above:

  • $url->segment(1) : class
  • $url->segment(2) : method

If argument null, it will return the last segment:

  • $url->segment() : other

I need suggestions for improvement this class, here is the code:

added 85 characters in body
Source Link
Zul
  • 123
  • 8
  1. http://localhost/myproject/class/method/arg/other (localhost)
  2. http://www.myproject.com/class/method/arg/other (live site)
  3. http://www.myproject.com/class/method/arg/other?param=value (with get param)

In both urls urls above:
$url->segment(1) : class
$url->segment(2) : method

  1. http://localhost/myproject/class/method/arg/other (localhost)
  2. http://www.myproject.com/class/method/arg/other (live site)

In both urls:
$url->segment(1) : class
$url->segment(2) : method

  1. http://localhost/myproject/class/method/arg/other (localhost)
  2. http://www.myproject.com/class/method/arg/other (live site)
  3. http://www.myproject.com/class/method/arg/other?param=value (with get param)

In urls above:
$url->segment(1) : class
$url->segment(2) : method

Source Link
Zul
  • 123
  • 8

URL Segment Class

I'm trying to create URL parse class., so i can check URL Segment / part,

Example:

  1. http://localhost/myproject/class/method/arg/other (localhost)
  2. http://www.myproject.com/class/method/arg/other (live site)

In both urls:
$url->segment(1) : class
$url->segment(2) : method

If argument null, it will return last segment:
$url->segment() : other

I need suggestions for improvement this class, here the code:

<?php
class url
{
    private $url;

    public function segment($arg=null)
    {
        if($arg==null)
        {
            $this->url = str_replace(BASEDIR,'',$_SERVER['REQUEST_URI']);
            
            if(isset($_GET))
            {
                $this->url = explode('?',$this->url);
                $this->url = $this->url[0];
            }
            
            $this->url = explode('/', trim($this->url, '/'));       
            

            return end($this->url);
        }
        else
        {
            $this->url = str_replace(BASEDIR,'',$_SERVER['REQUEST_URI']);
            if(isset($_GET))
            {
                $this->url = explode('?',$this->url);
                $this->url = $this->url[0];
            }

            $this->url = explode('/', trim($this->url, '/'));

            array_unshift($this->url, null);

            unset($this->url[0]);

            if(isset($this->url[$arg]))
            {
                return $this->url[$arg];
            }
            else
            {
                return null;
            }
        }
    }
}    
?>