Link to home
Start Free TrialLog in
Avatar of hankknight
hankknightFlag for Canada

asked on

Find text after last slash - PHP/REGEX

What is the best way to find the text after the last slash?

/ 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)));
 
?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Member_2_4694817
Member_2_4694817

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
... or use basename() like thehagman said.


Olly.
Avatar of hankknight

ASKER

basename() --- Why didn't I think of that?  Thanks for keeping it simple.