note 39269 added to function.strrchr
| From: | eshenk at comcast dot net | Date: | Thu, 22 Jan 2004 16:47:55 +0000 |
| Subject: | note 39269 added to function.strrchr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-64024@lists.php.net to get a copy of this message | ||
I use a showimage script to place an image into my website framework, and wanted a way to clean up
the file extension so it could be used in a header tag for a caption of sorts. I expanded the code
and heavily commented it for this note.
<?php
// Underscore and file extension murderizer
// By Enos Shenk
$text = "here_is_my_image.jpeg"; // Starting filename
$extension = strrchr($text, "."); // Get the file extension
$extlen = strlen($extension); // Length of extension
$len = strlen($text) - $extlen; // Get the length of the filename minus extension
$trimmed = substr($text,0,$len); // Only take the set length, no extension
$out = str_replace("_", " ", $trimmed); // Finally, replace _ with space
echo $out; // All done
?>
----
Manual Page -- http://www.php.net/manual/en/function.strrchr.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39269
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39269&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39269&report=yes
Search -- http://master.php.net/manage/user-notes.php