- substr: documentation ( source)
- strrpos: documentation ( source)
- preg_replace: documentation ( source)
<?php
// Everything you enter here will be executed by our servers. Try it!
$str = "safsad fd sm.pfle.jpg";
echo $a = strrpos($str,".");
$str2 = substr($str,0,$a);
$str3 = preg_replace("/[-, :;]/","_",$str2);
echo $str3;