Extracting Page Handle From URL


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

This will extract page handle between last slash and .html


Copy this code and paste it in your HTML
  1. $cur_path = JURI::current();
  2. $slash_pos = strrpos($cur_path,'/')+1;
  3. $dot_pos = strpos($cur_path,'.html');
  4. $page_len = $dot_pos!==false ? $dot_pos-$slash_pos : 0;
  5. if($page_len>0)
  6. $cur_page = substr($cur_path,$slash_pos,$page_len);
  7. else
  8. $cur_page = substr($cur_path,$slash_pos);
  9.  
  10. echo $cur_page;
  11.  
  12. e.g.
  13.  
  14. http://www.domain.com/somepage.html
  15.  
  16. output:
  17.  
  18. somepage

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.