Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing string in php 3

Status
Not open for further replies.

Tarnish

Technical User
Nov 13, 2006
221
US
HI all,

I need to parse the end of a string that is a windows file location. So the string looks like /
I want to get the index.php out of the string (and all strings like it).

Someone point me to a link or something? I've just started to work with php/mysql so every thing I take for granted in other environments is new here...

Thanks,
T
 
Use the basename function.

+++ Despite being wrong in every important aspect, that is a very good analogy +++
Hex (in Darwin's Watch)
 
As Don points out the basename() function is your best bet.
(You can click on the function name above to go to the manual page for it)
Also the PHP online manual is very well organized and detailed and will surely help you out.




----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for the replies!

That works well, though I need to write a function to modify the suffix part of that page according to the current pages file type.

I did look in the reference, but I didn't look in the file system area of the functions.

Thanks again,
T
 
use pathinfo(). that will return an array which includes the file type.
 
Thanks jpadie, I'll take a look at that. I figured out a way to get rid of the extensions but maybe I can do it cleaner with that.

thanks again,
T
 
Code:
<?php
function get_FileName($filename){
	$pi = pathinfo($filename);
	if (isset($pi['filename'])){ //only for php >= 5.2.0
		return $pi['filename'];
	} else {
		return basename($pi['basename'], $pi['extension']);
	}
}
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top