aobrien5 Posted October 7, 2008 Share Posted October 7, 2008 I've got a big switch/case statement to translate file names into readable text. Our programmers chose to use hex strings to describe different parts of the files, and all of my cases are working fine except one. switch ($profile) : <snip> case "00001800": $r .= " Live+7 ACM"; break; case "00001C00": $r .= " Live+75 ACM"; break; case "00000E00": $r .= " Live+3"; break; case "00000802": $r .= " Hispanic Live+7"; break; default: $r .= ""; endswitch; All of the cases above work fine (including those snipped) except case "00000E00". I've verified that the $profile contains the same string, but it get's translated as default. Is it being treated as a hex number for some reason? If so, why aren't all the others? I'm completely baffled on this one. I've tried storing the case string as a variable and that didn't help. I tried modifying the $profile and case to "10000E00" and that works fine. I tried modifying the $profile and case to "00001E00" and that ended up getting translated as a different number altogether. Does this mean I need to ensure that $profile is being treated as a string? How should I do that? Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/ Share on other sites More sharing options...
F1Fan Posted October 7, 2008 Share Posted October 7, 2008 Try using single quotes around the strings. That will tell the code to look at it literally, rather than trying to determine what it is (string, numberic, etc.). Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659229 Share on other sites More sharing options...
aobrien5 Posted October 7, 2008 Author Share Posted October 7, 2008 Actually, I did try that as well, and it didn't help. The more I write about this, the more I think it's related to the variable in $profile not being of the right format. That's being gathered from this part of the code: list($market, $period, $geography, $service, $profile, $other) = explode("_", $filename); where $filename = CHI_0807_12_00000004_00000E00_0 Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659248 Share on other sites More sharing options...
sasa Posted October 7, 2008 Share Posted October 7, 2008 '0000E00' means 0000*10^0 = 0 (float) change line case "00000E00": to case $profile==="00000E00": Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659250 Share on other sites More sharing options...
discomatt Posted October 7, 2008 Share Posted October 7, 2008 You could also try echo (string)$profile switch ( (string)$profile ) : Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659254 Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2008 Share Posted October 7, 2008 The bits of posted code actually work. That would mean that the $profile variable is being accessed as a number somewhere between where it is set and where it is tested in the switch/case statement. Please post the relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659256 Share on other sites More sharing options...
sasa Posted October 7, 2008 Share Posted October 7, 2008 The bits of posted code actually work. That would mean that the $profile variable is being accessed as a number somewhere between where it is set and where it is tested in the switch/case statement. Please post the relevant code. maybe not try <?php $a = '001'; switch ($a): case '1': echo 'ok'; break; default: echo 'no'; break; endswitch; ?> Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659259 Share on other sites More sharing options...
aobrien5 Posted October 7, 2008 Author Share Posted October 7, 2008 because $profile==="00000E00" doesn't work, I have to think $profile is being set as a float instead of a string when it's being exploded, right? Unfortunately, if I print it, it prints as 00000E00. Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659261 Share on other sites More sharing options...
PFMaBiSmAd Posted October 7, 2008 Share Posted October 7, 2008 Like I stated, just the posted pieces of code work - <?php $filename = "CHI_0807_12_00000004_00000E00_0"; list($market, $period, $geography, $service, $profile, $other) = explode("_", $filename); echo $profile; $r = ""; switch ($profile) : case "00001800": $r .= " Live+7 ACM"; break; case "00001C00": $r .= " Live+75 ACM"; break; case "00000E00": $r .= " Live+3"; break; case "00000802": $r .= " Hispanic Live+7"; break; default: $r .= ""; endswitch; echo $r; ?> You would need to post all the relevant code for anyone in a forum to be able to duplicate and find what exactly your code is doing. Edit: I'm going to take a guess that the variable gets passed as a parameter in a function call at some point. Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659268 Share on other sites More sharing options...
aobrien5 Posted October 7, 2008 Author Share Posted October 7, 2008 Actually that's fascinating. As I mentioned, I snipped a few cases above those posted. Put this case in as the first one, and it breaks: case "00000000": break; Edit: If you still want the whole function, I can post it. However, $profile is not passed into the function. Edit2: case $profile==="00000000" makes everybody happy. Quote Link to comment https://forums.phpfreaks.com/topic/127436-00000e00-not-being-treated-as-string/#findComment-659271 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.