In addition to having the image name all lowercase, I'd like to change any spaces to a dash.
<img src="/SC/images/<?php echo strtolower(the_title('','',false)); ?>-header.jpg" border="0" />
In addition to having the image name all lowercase, I'd like to change any spaces to a dash.
<img src="/SC/images/<?php echo strtolower(the_title('','',false)); ?>-header.jpg" border="0" />
Simple spaces can be removed using str_replace()
:
$image = "foo and bar.png";
// foo-and-bar.png
echo str_replace( " ", "-", $image );
A more complicated search/replace could be done using a regular expression:
$image = "foo2 and_ BAR.png";
// foo2-and_-bar.png
echo preg_replace( "/[^a-z0-9\._]+/", "-", strtolower($image) );
In this example, we permit letters a-z, numbers 0-9, periods and underlines - all other sequences of characters will be replaced with a single dash. The filename is converted to all lower-case prior to being ran through the replacement function.