lead2gold Posted June 8, 2006 Share Posted June 8, 2006 [code] /* $formObj is not known here */ if(is_int($formObj)){ $this->formObj = sprintf("%d", $formObj); }else if(is_float($formObj)){ $this->formObj = sprintf("%f", $formObj); else{ $this->formObj = $formObj; } /* $this->formObj is guarenteed to be a string at this point */[code]My question is... is there a function already that does this?[code] /* $formObj is not known here */ $this->formObj = thefunctioniwant($formObj); /* $this->formObj is guarenteed to be a string at this point */[/code]Sure i already wrote a basic version of it... but there are types i'm not checking (yet) like "bool" etc...I just want to know if there is something that will always returning a string equivalent ofwhatever was passed into it. I'll invent the wheel again if it hasn't been done...Chris Quote Link to comment https://forums.phpfreaks.com/topic/11517-converting-intfloatchar-string/ Share on other sites More sharing options...
nogray Posted June 8, 2006 Share Posted June 8, 2006 [a href=\"http://us3.php.net/manual/en/function.strval.php\" target=\"_blank\"]strval()[/a] Quote Link to comment https://forums.phpfreaks.com/topic/11517-converting-intfloatchar-string/#findComment-43371 Share on other sites More sharing options...
poirot Posted June 8, 2006 Share Posted June 8, 2006 Or use typecasting, like (string) $variable Quote Link to comment https://forums.phpfreaks.com/topic/11517-converting-intfloatchar-string/#findComment-43389 Share on other sites More sharing options...
Fyorl Posted June 9, 2006 Share Posted June 9, 2006 wouldn't sticking quotes "" around the variable do the trick as well? Quote Link to comment https://forums.phpfreaks.com/topic/11517-converting-intfloatchar-string/#findComment-43489 Share on other sites More sharing options...
Barand Posted June 9, 2006 Share Posted June 9, 2006 Yes, it would cast it as a string.There is also settype() function Quote Link to comment https://forums.phpfreaks.com/topic/11517-converting-intfloatchar-string/#findComment-43774 Share on other sites More sharing options...
lead2gold Posted June 11, 2006 Author Share Posted June 11, 2006 Thanks everyone, thats exactly what i was looking for! Quote Link to comment https://forums.phpfreaks.com/topic/11517-converting-intfloatchar-string/#findComment-44454 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.