Hey. I need help with an "unuplicating" string (AKA returning changes made to the string). I have a function in my PHP code that duplicates every character in a string ("Hello" becomes "HHeelllloo, etc.). Now I want to return this, and I do not know how (AKA I want to turn my "HHeelllloo" into "Hello").
Here is the code:
<?php
error_reporting(-1);
ini_set('display_errors', 1);
ini_set('output_buffering', 0);
?>
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Untitled 1</title>
</head>
<body>
<?php
if(isset($_POST["dupe"]) && !empty($_POST["input"])){
$input = $_POST["input"];
$newstring = "";
for($i = 0; $i < strlen($input); $i++){
$newstring .= str_repeat(substr($input, $i,1), 2);
}
echo $newstring;
}
if(isset($_POST["undupe"]) && !empty($_POST["input"])){
}
?>
<form method="post">
<input type="text" name="input" placeholder="Input"></input><br><br>
<button type="submit" name="dupe">Dupe</button>
<button type="submit" name="undupe">Undupe</button>
</form>
</body>
</html>
Now I do not know what to do when I click the "undupe" button. (By the way, sorry if I made any mistakes in this post. Im new to stackoverflow.).
source
share