Jump to content

strrpos and substr


corillo181

Recommended Posts

this code changes the name of a uploading file

but i dont know how it works can someone explaing it to me? i tried php.net but is not making sense .


[code]
$genre=$_POST['genre'];
$filename = $_FILES['sfile']['name'];
$pos = strrpos($filename, '.');
$newname = $song . substr($filename, $pos);
[/code]
Link to comment
https://forums.phpfreaks.com/topic/29612-strrpos-and-substr/
Share on other sites

Yes.

The strrpos finds the position of the last occurance of a string and returns that value as an integer.  substr truncates a string at position x (and y if specified).  Like so:

File Name: myfile.mpeg
$pos = strrpos('myfile.mpeg','.'); // returns 6 (6th position)
substr('myfile.mpeg',$pos); // removes everything except .mpeg

Do you understand?
Link to comment
https://forums.phpfreaks.com/topic/29612-strrpos-and-substr/#findComment-135886
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.