Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/152214-string-handeling/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/152214-string-handeling/#findComment-799348
Share on other sites

$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 />';

Link to comment
https://forums.phpfreaks.com/topic/152214-string-handeling/#findComment-799356
Share on other sites

$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

Link to comment
https://forums.phpfreaks.com/topic/152214-string-handeling/#findComment-799359
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.