str_replace in 2 Textboxen

07/26/2017 19:59 sexualising#1
Hallo!

Will folgendes realisieren:
Es gibt 2 Textboxen. In eine Textbox schreibt man seinen Text rein und in der anderen wird der Text instant angezeigt, aber es werden die normal Buchstaben durch breite Buchstaben ersetzt.

Das hab ich bis jetzt:
main.php
Code:
<?php
if ($_POST) {
$post = 'input' => $_POST['input'],;
$ch = curl_init('replace.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
}
?>
<form action="" method="POST">
	<input type="text" name="input"/>
	<input hidden value="<?php echo $_SERVER["SCRIPT_NAME"]; ?>" name="from"/>
	<input type="submit" value="ok"/>
</form>
<?php if ($_POST) : ?>
	<input type="text" name="output" value="<?php echo $response; ?>" />
<?php endif; ?>
replace.php
Code:
<meta charset="utf-8" class="__web-inspector-hide-shortcut__">
<?php
$text = $_POST['input'];
$normal = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '0', '1
', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$', '%', '&', '\'', '(', ')', '*', '+', '-', '.', ',', '/', ':', ';', '<', '>', '@', '=', '?', '[', ']', '{', '}', '~', '|', '_');
$wide = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "\x20", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", "#", "$", "%", "&", "'", "(", ")", "*", "+", "-", ".", ",", "/", ":", ";", "<", ">", "@", "=", "?", "[", "]", "{", "}", "~", "|", "_");
echo str_replace($normal, $wide, $text);
?>
Wenn ich das ganze ausführen will, kommt folgender Fehler:
Quote:
Parse error: syntax error, unexpected T_DOUBLE_ARROW in F:\Programs\xampp\htdocs\main.php on line 3​
07/26/2017 20:12 Mikesch01#2
Tag. Der Code in Zeile 3 macht keinen Sinn.

PHP Code:
$post 'input' => $_POST['input'],; 
Was genau hast du da vor? Wolltest du ein Array machen? Wenn ja, dann muss es so heißen:
PHP Code:
$post = array('input' => $_POST['input']); 
Wobei du in $_POST eigentlich schon die Information gespeichert hast.

p.s warum verwendest du hier CURL? Du rufst doch eine Datei im eigenen Host auf. Da reicht eigentlich ein require/include Befehl.
07/26/2017 21:02 sexualising#3
Quote:
Originally Posted by Mikesch01 View Post
p.s warum verwendest du hier CURL? Du rufst doch eine Datei im eigenen Host auf. Da reicht eigentlich ein require/include Befehl.
Kenne mich nicht so gut in PHP aus. Habe das meiste aus einem anderen Forum und von Github.
Weiß nicht genau ich wie das mit 2 Textboxen realisiere so wie ich es oben beschrieben habe.
07/26/2017 22:13 Syc#4
Warum machst du das nicht einfach mit Javascript?
07/26/2017 23:19 sexualising#5
Quote:
Originally Posted by Syc View Post
Warum machst du das nicht einfach mit Javascript?
"einfach"
Ja wenn ich's könnte. Dachte mit php ist das leichter. :p
08/01/2017 14:34 iMostLiked#6
Hey,

du kannst das jQuery on-input Event nutzen, um den Text einer Textbox instant in eine andere Textbox zu übertragen. Hier ein kleines Beispiel:

Code:
<input type="text" id="textbox1">
<input type="text" id="textbox2">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$('#textbox1').on('input', function() {
    $('#textbox2').val($(this).val());
});
</script>