Binary string testing... - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of Binary string testing....php

  1. <?php
  2.     function estBinaire($chaine) {
  3.         $bin=true;
  4.         for ($i=0; $i<strlen($chaine); $i++) {
  5.             if (!(($chaine[$i]=='0') || ($chaine[$i]=='1'))) {
  6.                 $bin=false;
  7.             }
  8.         }
  9.         if ($bin==true) {
  10.             echo 'BINAIRE'."\n";
  11.         } else {
  12.             echo 'NON BINAIRE'."\n";
  13.         }
  14.     }
  15.     
  16.     estBinaire('11001');
  17.     estBinaire('101010010010a010101010');
  18.     estBinaire('1');
  19.     estBinaire('0');
  20.     estBinaire('11201');
  21.     
  22.  
File Description
  • Binary string testing...
  • PHP Code
  • 12 Dec-2019
  • 495 Bytes
You can Share it: