strip_tags and trim not working properly
<p>I am making a meme generator, Imagick generating the images. My problem is that even if I do some operations on the string I use for the image, the output is incorrect.</p>

<p>By example:</p>

<pre><code>$_POST['text_top'] = " test test&lt;br&gt;"; //(starts with a space)
</code></pre>

<p>Then I do:</p>

<pre><code>$text_top = strip_tags(trim($_POST['text_top']));
</code></pre>

<p>But on the display of $text_top, after I paste the variable on the image, I get:</p>

<pre><code>&amp;nbsptest test&amp;lt;br&amp;gt;
</code></pre>

<p>Why does it happen if I'm calling strip_tags and trim, from what I see, correct and as usual?</p>

<p>All is UTF8 encoded.</p>

<p>Thank!</p>

<p>EDIT: (full code)</p>

<pre><code>function wordWrapAnnotation(&amp;$image, &amp;$draw, $text, $maxWidth)
{
$words = explode(" ", $text);
$lines = array();
$i = 0;
$lineHeight = 0;
while($i &lt; count($words) )
{
    $currentLine = $words[$i];
    if($i+1 &gt;= count($words))
    {
        $lines[] = $currentLine;
        break;
    }
    //Check to see if we can add another word to this line
    $metrics = $image-&gt;queryFontMetrics($draw, $currentLine . ' ' . $words[$i+1]);
    while($metrics['textWidth'] &lt;= $maxWidth)
    {
        //If so, do it and keep doing it!
        $currentLine .= ' ' . $words[++$i];
        if($i+1 &gt;= count($words))
            break;
        $metrics = $image-&gt;queryFontMetrics($draw, $currentLine . ' ' . $words[$i+1]);
    }
    //We can't add the next word to this line, so loop to the next line
    $lines[] = $currentLine;
    $i++;
    //Finally, update line height
    if($metrics['textHeight'] &gt; $lineHeight)
        $lineHeight = $metrics['textHeight'];
}
return array($lines, $lineHeight);
}

$text_top = strip_tags(trim($_REQUEST['text_top']));
$text_bottom = strip_tags(trim($_REQUEST['text_bottom']));
$id_base = trim($_REQUEST['id_base']);

/* Création d'un nouvel objet imagick */
$im = new Imagick($_REQUEST['image']);

/* Création d'un nouvel objet imagickdraw */
$draw = new ImagickDraw();

/* Définition de la taille du texte à 52 */
$draw-&gt;setFontSize(52);
$draw-&gt;setTextAlignment(2);
$draw-&gt;setFont("impact.ttf");
$draw-&gt;setFillColor('white');
$draw-&gt;setStrokeColor("black");
$draw-&gt;setStrokeWidth(1);

/* Ajout d'un texte */
//$draw-&gt;annotation($im-&gt;getImageWidth()/2, 50, $text);
list($lines, $lineHeight) = wordWrapAnnotation($im, $draw, stripslashes($text_top), $im-&gt;getImageWidth());
$posY= 50;
for($i = 0; $i &lt; count($lines); $i++){
$draw-&gt;annotation($im-&gt;getImageWidth()/2, $posY + $i*$lineHeight, $lines[$i]);
}

$im-&gt;drawImage($draw);
</code></pre>
