Jump to content

String handeling...


louis_coetzee

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.