I have this line.
$line = '/opt/fings/interface/20140905111645811106.txt 0';
I used this to trip the trailing 0/r/n
.
$pos = strpos($lines[$x], ' ');
$file = '.'.substr($lines[$x], 0, $pos);
so I'm left with this /opt/fings/interface/20140905111645811106.txt
But I need the filename alone. e.g. 20140905111645811106.txt
Ho do I grab the string from the back up to the first occurrence of a slash?
For example, backslashes are used in non-relative path C:\Program Files (x86)\Microsoft Office\Office16. Yet, for a relative path, Windows adopts forward slashes. While in Mac, Linux, Android, Chrome, and Steam, all Unix-like operating systems, directories in file paths are separated by forward slashes.
Because relative path names specify a path starting in the current directory, they do not begin with a slash (/). Relative path names are used to specify the name of a file in the current directory or the path name of a file or directory above or below the level of the current directory in the file system.
If I recall correctly, backslash is used to denote something within the current computer or network such as C:\Windows or \\172.12. 1.34, while forward slashes are used to denote something that is outside or external to the current computer or network such as http://www.google.com/.
Windows uses the backslash ( \ ) for the file system delimiter. For everything else the forward slash is used ( / ). The Uri type uses the forward slash because that is how a uniform resource identifier is defined.
You can use basename()
in this case:
$line = '/opt/fings/interface/20140905111645811106.txt';
echo basename($line); // 20140905111645811106.txt
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With