Jump to content

[SOLVED] PHP syntax


regdude

Recommended Posts

Hi!

$bin .= strlen(decbin(ord($txt_str[$i]))) < 8 ? str_pad(decbin(ord($txt_str[$i])), 8, 0, str_pad_left) : decbin(ord($txt_str[$i]));  

Got this line, but I don't understand a few things.

For starters, it doesn't work, but will find out why after I will understand how it works.

I understand all parts except "< 8 ?" and ":".

What they do?

Link to comment
https://forums.phpfreaks.com/topic/159285-solved-php-syntax/
Share on other sites

It's using a ternary operator.  The equivalent in an if/else is:

 

if(strlen(decbin(ord($txt_str[$i]))) 
{
   $bin .=  str_pad(decbin(ord($txt_str[$i])), 8, 0, str_pad_left);
}
else
{
   $bin .= decbin(ord($txt_str[$i])); 
}

 

For starters, it doesn't work

 

Can't really help you unless you provide some more information.

Link to comment
https://forums.phpfreaks.com/topic/159285-solved-php-syntax/#findComment-840093
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.