remove everything after slash

Whats the best way to remove everything after the trailing slash

so if i had

http://www.somesite.com/sometext

i would want it to show

http://www.somesite.com/

regards

pete
LVL 1
peter2001Asked:
Who is Participating?
 
Blue-hitCommented:
Either use an framework like Zend framework with its URL/Baseurl functions or do it via string manipulation as shown in code attachment.

The line takes your original string, finds the first occurende of //, and goes from there (exluding the //, what is the meaning of the +2) to the next /, then it adds 1 more character to include teh final / you mentioned.

<?php 
  $string = 'http://www.somesite.com/sometext';
  $newString = substr ( $string, 0 , (strpos($string,'/',strpos($string,'//')+2))+1 );		
  echo($newString);
?>

Open in new window

0
 
peter2001Author Commented:
That works great thanks for the help
0
 
peter2001Author Commented:
cheers and thanks for the explanation
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.