first of all, I am a noob in PHP. I am trying to achieve something like this.
I have a photo named "Test Image.jpg". Then, the image tag inside some other php functions. Is there a way that I could show the filename without the extensions (in this case Test Image), as the title of that image?
Here is my code:
<? foreach($dy_matmirat as $key => $image) : ?>
<td valign="top"><img src="images/<?=$image->filename?>" width="70" /></td>
<td valign="top">Mesatarja: <?=$image->wins-$image->losses?></td>
<? endforeach ?>
I hope that somebody can help me. Thanks a lot.
Use the basename() function.
<?=basename($image->filename, '.jpg')?>
This will strip the extension from your filename.
Edit: forgot the second parameter.
This solution works if you know by advance the extension you want to remove.
You can also use pathinfo():
$fileparts = pathinfo("Test Image.jpg");
echo $fileparts['filename']; // prints Test Image
$name = $image->filename;
$name = substr($name,0,strripos($name,"."));
echo $name;