Jump to content

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

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.