Checking function with spaces in it in php
<p>I am using this query</p>

<pre><code>"SELECT * FROM items WHERE itemname LIKE '%$name%'"
</code></pre>

<p>If <code>$name="alex"</code>, then the query returns the correct information. But if  <code>$name="alex  "</code> with trailing whitespace, then no results are returned.</p>

<p>If <code>$name="alex dude"</code>, then this is valid, but <code>$name="alex dude "</code> is not. I only want to remove whitespace at the end of the string.</p>

<p>I have written a function to clear out spaces at the end of name. This is the function.</p>

<pre><code>function checkname($dataname)
{
    $func_name ="";
    $checker = substr($dataname, -1);
    if($checker == " ")
    {
        $func_name = substr_replace($dataname, "", -1)
        function checkname($dataname);
    }
    else
    {
        $dataname = $func_name;
    }
    return $dataname;
}
</code></pre>

<p>This gives me a PHP Parse error:</p>

<blockquote>
  <p>syntax error, unexpected 'function' (T_FUNCTION) in C:\inetpub\vhosts\httpdocs\compare.php on line 176`.</p>
</blockquote>

<p>I don't understand why recursively calling a function is giving me an error. </p>

<p>Can you guys help out with this? Is there a better solution or better SQL query than I am using?</p>