[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 473
  • Last Modified:

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
0
peter2001
Asked:
peter2001
  • 2
1 Solution
 
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now