hankknight
asked on
Find text after last slash - PHP/REGEX
What is the best way to find the text after the last slash?
/ or \
/ or \
<?php
$file = '/dsafdsf/adsfadsf/asdfdasf/adsf/test.txt';
echo trim(str_replace('_', ' ' , substr($file, strrpos($file,'/') + 1)));
echo '<hr />';
$file = 'c:\\dsafdsf\\adsfadsf\\asdfdasf\\adsf\\test.txt';
echo trim(str_replace('_', ' ' , substr($file, strrpos($file,'/') + 1)));
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
basename() --- Why didn't I think of that? Thanks for keeping it simple.
Olly.