Forum Moderators: coopster

Message Too Old, No Replies

Remove slash from beginning of string

         

JeremyL

10:02 pm on Sep 22, 2006 (gmt 0)

10+ Year Member



I have a string, "/index.html". I need to return "index.html" without the string. What expression would I use with preg_replace() to accomplish this?

I know the format, I just such at regex.

eelixduppy

10:06 pm on Sep 22, 2006 (gmt 0)



Maybe this:

$string = "/index.html";
$pattern = "/^\//";
$str = preg_replace($pattern,"",$string);

I'm not that great with Regex either ;)

Good luck!

Psychopsia

10:15 pm on Sep 22, 2006 (gmt 0)

10+ Year Member



An alternative is to use basename [us2.php.net] function:

$str = '/index.html';
$str = basename($str);

JeremyL

11:11 pm on Sep 22, 2006 (gmt 0)

10+ Year Member



Perfect. Thanks