louis_coetzee Posted April 2, 2009 Share Posted April 2, 2009 Hi, I have a db entry called capability the capability of a language by a person. For Example: Language Afrikaans: RWS English: RS etc. R = READ ; W = WRITE ; S = SPEAK Now what I want to do is, get this from the db to be able to edit this: $capability = $row['capability']; I need to identify which one's he is capable of: $r = true; $w = false; $s = true; Can anyone tell me how to do this? I did do a search on google, but still did not het clarity. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/152214-string-handeling/ Share on other sites More sharing options...
gaza165 Posted April 2, 2009 Share Posted April 2, 2009 Show us what code you have already done and we will work from there. Remember to encase your code in the [ code ] tags. Quote Link to comment https://forums.phpfreaks.com/topic/152214-string-handeling/#findComment-799312 Share on other sites More sharing options...
louis_coetzee Posted April 2, 2009 Author Share Posted April 2, 2009 the $capability variable is the one I am working with, like I said it will contain at most RWS, I don't have code, because I don't know how to search for 'R' in $capability, I want to search for example 'R' and if it is in the string, must return true, else false. Quote Link to comment https://forums.phpfreaks.com/topic/152214-string-handeling/#findComment-799348 Share on other sites More sharing options...
Mark Baker Posted April 2, 2009 Share Posted April 2, 2009 $capability = 'RW'; $r = $w = $s = false; for($i = 0; $i < strlen($capability); $i++) { $tmp = strtolower($capability{$i}); $$tmp = true; } echo 'Read = '.(($r) ? 'True' : 'False').'<br />'; echo 'Write = '.(($w) ? 'True' : 'False').'<br />'; echo 'Speak = '.(($s) ? 'True' : 'False').'<br />'; Quote Link to comment https://forums.phpfreaks.com/topic/152214-string-handeling/#findComment-799356 Share on other sites More sharing options...
louis_coetzee Posted April 2, 2009 Author Share Posted April 2, 2009 $capability = 'RW'; $r = $w = $s = false; for($i = 0; $i < strlen($capability); $i++) { $tmp = strtolower($capability{$i}); $$tmp = true; } echo 'Read = '.(($r) ? 'True' : 'False').'<br />'; echo 'Write = '.(($w) ? 'True' : 'False').'<br />'; echo 'Speak = '.(($s) ? 'True' : 'False').'<br />'; Thanks a lot, solves the problem, just for interest sake, ps I am a beginner... how does the $$tmp (two dollar signs) work? thanks Quote Link to comment https://forums.phpfreaks.com/topic/152214-string-handeling/#findComment-799359 Share on other sites More sharing options...
Showcase Posted April 2, 2009 Share Posted April 2, 2009 The "double dollar signs" are called variable variables. http://www.php.net/manual/en/language.variables.variable.php Quote Link to comment https://forums.phpfreaks.com/topic/152214-string-handeling/#findComment-799368 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.