if I have a file name stored as a string how can i remove the file extension?
Example:
$var = "toys.jpg"
and I need just the toys and not the jpg....
$var = "toys.jpg"; $newvar = preg_replace("#^(.*)\.[A-Za-z\.]+$#", "\\1", $var); echo $newvar;
The regular expression should pull the file name from any type of file. Even tarballs.
Could be done easier, can't it?
[INDENT]$var = explode(".", 'toys.jpg');[/INDENT]
Ya
You will have an array with the results. just have to say
var[0] or var[1] depending on what u want
...putting it altogether then:
$var = 'toys.jpg'; $name = explode('.', $var); echo $name[0];
gives you 'toys' - just like santa clause.