Extracting Path and Query String from Any URL String


/ Published in: PHP
Save to your folder(s)

You can use JUri object to extract the path or query string from a any url


Copy this code and paste it in your HTML
  1. //current page
  2. $uri = JUri::getInstance();
  3.  
  4. //another link
  5. $uri = JUri::getInstance('/somedomain.com/subdir/page.html?param=val');
  6.  
  7. //Will extract ?param=val
  8. $qry = $uri->toString(array('query'));
  9.  
  10. //Will extract /somedomain.com/subdir/page.html
  11. $path = $uri->toString(array('path'));

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.