-1

I have read so much that I have confused myself beyond reason.

What I want (with PHP) is to be able to get the url of the current page, and then strip out a specific word and have it displayed on the page.

Example url: http://domain.com/some/thing/word

Example output: http://domain.com/some/thing/

So far I managed to do one or the other but break things when I try to do it all together.

Any help greatly appreciated.

VMai
  • 10,156
  • 9
  • 25
  • 34

1 Answers1

0

You could try the below code to remove the last word charcters in your URL,

<?php
echo preg_replace('~^(.*\/).*$~', '$1', 'http://domain.com/some/thing/word');
?> //=> http://domain.com/some/thing/
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274