<?php
function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

$obfuscated_code = "";
if(isset($_POST['submit'])) {
    $input_code = $_POST['input_code'];

    $code_lines = explode("\n", $input_code);
    $variable_names = array();
    $function_names = array();
    foreach($code_lines as $line) {
        preg_match_all('/\$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $line, $matches);
        $variable_names = array_merge($variable_names, $matches[0]);
        preg_match_all('/function\s+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $line, $matches);
        $function_names = array_merge($function_names, $matches[0]);
    }
  
    $variable_names = array_unique($variable_names);
    $function_names = array_unique($function_names);
    $obfuscated_variable_names = array();
    $obfuscated_function_names = array();
    foreach($variable_names as $variable_name) {
        $obfuscated_variable_name = generateRandomString(5).$variable_name;
        while(in_array($obfuscated_variable_name, $obfuscated_variable_names)) {
            $obfuscated_variable_name = generateRandomString(5).$variable_name;
        }
        $input_code = str_replace($variable_name, $obfuscated_variable_name, $input_code);
        $obfuscated_variable_names[] = $obfuscated_variable_name;
    }
    foreach($function_names as $function_name) {
        $obfuscated_function_name = generateRandomString(5).str_replace("function ", "", $function_name);
        while(in_array($obfuscated_function_name, $obfuscated_function_names)) {
            $obfuscated_function_name = generateRandomString(5).str_replace("function ", "", $function_name);
        }
        $input_code = str_replace($function_name, $obfuscated_function_name, $input_code);
        $obfuscated_function_names[] = $obfuscated_function_name;
    }

    $input_code = preg_replace_callback('/(\"|\')(.*?)(\"|\')/', function($matches) {
        $string = $matches[2];
        $string = str_split($string);
        $obfuscated_string = "";
        foreach($string as $char) {
            $obfuscated_string .= "\\x".dechex(ord($char));
        }
        return $matches[1].$obfuscated_string.$matches[3];
    }, $input_code);

    $obfuscated_code = $input_code;
}
?>
<form method="post">
  <textarea name="input_code" rows="10" cols="50"></textarea><br>
  <input type="submit" name="submit" value="Başlat">
</form>
<textarea rows="10" cols="50">
  <?php echo $obfuscated_code; ?>
</textarea>