I am using a simple PHP & HTML script which lets the user type a text, and the script converts the input to binary. When opening the script however, I see this in the input box:
Image attached And nothing happens when I'm pressing the submit button. Can somebody help me solve the issue? code is provided below.
<?php
// Initialize the input and binary variables
$input = '';
$binary = '';
// Check if the form has been submitted
if(isset($_POST['submit'])) {
$input = $_POST['input'];
// Convert the input text to binary
for ($i = 0; $i < strlen($input); $i++) {
$binary .= decbin(ord($input[$i])) . ' ';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Text to Binary Converter</title>
</head>
<body>
<form method="post">
<label for="input">Enter text to convert:</label><br>
<textarea id="input" name="input" rows="4" cols="50"><?php echo $input; ?></textarea><br>
<input type="submit" name="submit" value="Convert">
</form>
<?php if(!empty($binary)) { ?>
<p>
Binary conversion of "<?php echo $input; ?>":<br>
<?php echo $binary; ?>
</p>
<?php } ?>
</body>
</html>
I tried changing some code but nothing worked, there is always the same thing.