How to detect padding on an integer and treat it as a string?

Posted by Sirber on Stack Overflow See other posts from Stack Overflow or by Sirber
Published on 2010-04-30T15:14:55Z Indexed on 2010/04/30 15:17 UTC
Read the original article Hit count: 153

Filed under:
|
|
|

I have this function to prepare variable to be used in a SQL query:

function sqlize($mInput)
{
    if (!isset($mInput))
        $mInput = "null";

    elseif (strtolower($mInput) == "null") { }

    elseif (is_numeric($mInput)) { }

    elseif (is_string($mInput))
    {
        $mInput = trim($mInput);
        $mInput = addslashes($mInput);
        $mInput = '"' . $mInput . '"';
    }
    else
        $mInput = "null";
    return $mInput;
}

I have a string "0004", which is going in a "varchar field", is cought by is_numeric, and is saved as "4" and not "0004". Is there a way to detect the padding and process it as a string?

Thank you!

© Stack Overflow or respective owner

Related posts about php

Related posts about string-manipulation