It won't work because accents aint allowed in a file name.
A workaround: Try naming your image file with accents with a supported name. Eg: é
=> eacute
With this code:
<?php
$q = "my phrase with special chars like úção!?";
while ($i < strlen($q)) {
if ($q[$i] == " ")
{
echo '<img src="space.png" />';
} else if ($q[$i] == "?") {
echo '<img src="questionmark.png" />';
} else {
echo '<img src="'.str_replace(array("&", ";"), "", htmlentities($q[$i])).'.png" />';
}
$i++;
}
?>
This code also support space. You need an image named space.png though.
Here is the generated output:
<img src="m.png" /><img src="y.png" /><img src="space.png" /><img src="p.png" /><img src="h.png" /><img src="r.png" /><img src="a.png" /><img src="s.png" /><img src="e.png" /><img src="space.png" /><img src="w.png" /><img src="i.png" /><img src="t.png" /><img src="h.png" /><img src="space.png" /><img src="s.png" /><img src="p.png" /><img src="e.png" /><img src="c.png" /><img src="i.png" /><img src="a.png" /><img src="l.png" /><img src="space.png" /><img src="c.png" /><img src="h.png" /><img src="a.png" /><img src="r.png" /><img src="s.png" /><img src="space.png" /><img src="l.png" /><img src="i.png" /><img src="k.png" /><img src="e.png" /><img src="space.png" /><img src="uacute.png" /><img src="ccedil.png" /><img src="atilde.png" /><img src="o.png" /><img src="!.png" /><img src="questionmark.png" />