3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = "Ваc зовут O\'reilly? \\/\\/\\"; function utf8_to_cp1251($s) { for ($c=0;$c<strlen($s);$c++) { $i=ord($s[$c]); if ($i<=127) $out.=$s[$c]; if ($byte2){ $new_c2=($c1&3)*64+($i&63); $new_c1=($c1>>2)&5; $new_i=$new_c1*256+$new_c2; if ($new_i==1025){ $out_i=168; } else { if ($new_i==1105){ $out_i=184; } else { $out_i=$new_i-848; } } $out.=chr($out_i); $byte2=false; } if (($i>>5)==6) { $c1=$i; $byte2=true; } } return $out; } echo utf8_to_cp1251($str);
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Warning: Undefined variable $byte2 in /in/L6XGC on line 10 Warning: Undefined variable $out in /in/L6XGC on line 23 ��c ����� O\'reilly? \/\/\
Output for 5.0.4 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.37, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
Notice: Undefined variable: byte2 in /in/L6XGC on line 10 Notice: Undefined variable: out in /in/L6XGC on line 23 ��c ����� O\'reilly? \/\/\
Output for 7.3.32 - 7.3.33, 7.4.26
��c ����� O\'reilly? \/\/\
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9, 5.0.0 - 5.0.3
Notice: Undefined variable: byte2 in /in/L6XGC on line 10 Notice: Undefined variable: out in /in/L6XGC on line 23 ��c ����� O\'reilly? \/\/\

preferences:
293.78 ms | 402 KiB | 365 Q