# Removing characters form a string

**URL:** <https://forum.kirupa.com/t/removing-characters-form-a-string/204547>\
**Category:** Uncategorized\
**Created:** [October 20, 2006, 6:01pm UTC](https://forum.kirupa.com/t/removing-characters-form-a-string/204547 "2006-10-20T18:01:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramblerob](https://avatars.discourse-cdn.com/v4/letter/r/8c91f0/32.png) [@ramblerob](https://forum.kirupa.com/u/ramblerob)\
**Post date:** [October 20, 2006, 6:01pm UTC](https://forum.kirupa.com/t/removing-characters-form-a-string/204547/1 "2006-10-20T18:01:55Z")

</div>

I have a string variable that consists of a url. Basically it is “[http://www.anydomain.com/anypage.htm](http://www.anydomain.com/anypage.htm)” The domain will be varied in length and the amount of “/”'s will vary as well.

So the string could be any of the folowing:

[http://www.anydomain.com/anypage.htm](http://www.anydomain.com/anypage.htm)  
[http://www.any.com/anypage.htm](http://www.any.com/anypage.htm)  
[http://www.anydomain.com/page.htm](http://www.anydomain.com/page.htm)  
[http://www.anydomain.com/sub/sub/page.htm](http://www.anydomain.com/sub/sub/page.htm)

What I need to do is strip out everything except the stuff after the last “/” … basically leaving me with the page name.

Is preg\_replace the easiest way to do this?

If so, what would the code look like… preg\_replace looks pretty compliacated.

Thanks?
