Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 742417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T08:44:44+00:00 2026-05-14T08:44:44+00:00

I was searching here on StackOverflow about converting string to the real value and

  • 0

I was searching here on StackOverflow about converting string to the real value and i didn’t found.
I need a function like “gettype” that does something like the result above, but i can’t do it all :s

gettypefromstring("1.234"); //returns (doble)1,234;
gettypefromstring("1234"); //returns (int)1234;
gettypefromstring("a"); //returns (char)a;
gettypefromstring("true"); //returns (bool)true;
gettypefromstring("khtdf"); //returns (string)"khtdf";

Thanks to all 🙂

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T08:44:45+00:00Added an answer on May 14, 2026 at 8:44 am

    1+ for Svisstack! 😉

    Here is the function if someone want it:

    function gettype_fromstring($string){
        //  (c) José Moreira - Microdual (www.microdual.com)
        return gettype(getcorrectvariable($string));
    }
    function getcorrectvariable($string){
        //  (c) José Moreira - Microdual (www.microdual.com)
        //      With the help of Svisstack (http://stackoverflow.com/users/283564/svisstack)
    
        /* FUNCTION FLOW */
        // *1. Remove unused spaces
        // *2. Check if it is empty, if yes, return blank string
        // *3. Check if it is numeric
        // *4. If numeric, this may be a integer or double, must compare this values.
        // *5. If string, try parse to bool.
        // *6. If not, this is string.
    
        $string=trim($string);
        if(empty($string)) return "";
        if(!preg_match("/[^0-9.]+/",$string)){
            if(preg_match("/[.]+/",$string)){
                return (double)$string;
            }else{
                return (int)$string;
            }
        }
        if($string=="true") return true;
        if($string=="false") return false;
        return (string)$string;
    }
    

    I used this function to know if the number X is multiple of Y.

    Example:

    $number=6;
    $multipleof=2;
    if(gettype($number/$multipleof)=="integer") echo "The number ".$number." is multiple of ".$multipleoff.".";
    

    But the framework that i work returns always the input vars as strings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was searching here about converting a string like 16:20 to a DateTime type
I tried searching here for a similar solution but didn't see one so I
I see the terms managed and unmanaged used a fair bit around here. Searching
Searching for some sample code for converting a point in WGS84 coordinate system to
Searching for a string within a string is extremely well supported in .NET but
After searching online, the best solution I've found so far is to just make
I have googled a lot and also searched in stackoverflow.com about how to sort
Im looking to make my own implementation of these Identicons or Gravatars found here
I'm building a rails app that takes information about products from an XML datafeed
this is my first question on StackOverflow, but I think that we'll both come

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.