Forum Moderators: coopster
$string = "image.jpg";
$new_string = [url=http://us2.php.net/manual/en/function.str-replace.php]str_replace[/url](".jpg","",$string);
echo $new_string;
Good luck!
* with str_replace the position of the substring within the string cannot be taken into account. So if the filename is something odd like "foo.jpgbar.doc", using str_replace as in eelixduppy's example would result in "foobar.doc".
* preg_replace as used in the other example does not have that disadvantage. But it does use a regular expression, and matching such patterns requires more server resources. Hardly noticeable, but present.
Conclusion: if you're sure that there will not be weird filenames as "foo.jpgbar.doc", use str_replace. Otherwise, use preg_replace.
$string = "image.jpg";
$new_string = [url=http://us2.php.net/manual/en/function.basename.php]basename[/url]($string,".jpg");
echo $new_string;
I'm not sure if the suffix parameter is case-sensitive or not.
I guess you really do learn something new every day. In my case, more than just something, but many things. ;)