Allen4172 Posted May 19, 2006 Share Posted May 19, 2006 I've tried a couple of things and can't seem to get it to work properly.I'm attempting to check if a value is NULL. I've tried things like:[code]if($variable$ == NULL) { $php_var = 0;}[/code]The variable isn't from PHP, its from a CMS system, that uses its variables as $something$. With this system, if nothing is typed in, its just blank spaces and the php would see:[code]if( == NULL){ $php_var = 0;}[/code]I'm trying to make it to where, if nothing was entered in, and the script sees the blank, then it would auto put it as 0. Any help or ideas would be appreciated. :) Quote Link to comment https://forums.phpfreaks.com/topic/9967-check-to-see-if-value-is-null/ Share on other sites More sharing options...
alpine Posted May 19, 2006 Share Posted May 19, 2006 im not sure i follow, but in a lack of responce - her is a suggestion on setting variables if they don't exist or is false (0):[code] if(!$var){$var = "whatever";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9967-check-to-see-if-value-is-null/#findComment-37161 Share on other sites More sharing options...
Michael4172 Posted May 19, 2006 Share Posted May 19, 2006 Thanks for the reply.In that scenerio when that field is false ($example$) the php sees:[code]if(!){$var = "whatever";}[/code]It then gives an error of [b]Parse error: parse error, unexpected ')'[/b] Quote Link to comment https://forums.phpfreaks.com/topic/9967-check-to-see-if-value-is-null/#findComment-37226 Share on other sites More sharing options...
dsk3801 Posted May 20, 2006 Share Posted May 20, 2006 [code]$var = '$variable$';if (strlen($var) == 0){ $var = 0;}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/9967-check-to-see-if-value-is-null/#findComment-37365 Share on other sites More sharing options...
Orio Posted May 20, 2006 Share Posted May 20, 2006 [a href=\"http://www.php.net/manual/en/function.is-null.php\" target=\"_blank\"]http://www.php.net/manual/en/function.is-null.php[/a]....Orio. Quote Link to comment https://forums.phpfreaks.com/topic/9967-check-to-see-if-value-is-null/#findComment-37404 Share on other sites More sharing options...
Michael4172 Posted May 20, 2006 Share Posted May 20, 2006 [!--quoteo(post=375438:date=May 19 2006, 11:24 PM:name=Dave K.)--][div class=\'quotetop\']QUOTE(Dave K. @ May 19 2006, 11:24 PM) [snapback]375438[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]$var = '$variable$';if (strlen($var) == 0){ $var = 0;}[/code][/quote]Thanks Dave, that is exactly what I needed and it now works :) I tried something similar earlier, but I didn't put the single quotes around $variable$ from above. Quote Link to comment https://forums.phpfreaks.com/topic/9967-check-to-see-if-value-is-null/#findComment-37464 Share on other sites More sharing options...
Houdini Posted May 20, 2006 Share Posted May 20, 2006 There is always empty() as per [a href=\"http://us3.php.net/empty\" target=\"_blank\"]empty()[/a] in the PHP Manual. Quote Link to comment https://forums.phpfreaks.com/topic/9967-check-to-see-if-value-is-null/#findComment-37484 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.