str_replace in 2 Textboxen

  • PHP

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von Acr0most.

    str_replace in 2 Textboxen

    Hallo Community!

    Brauche etwas Hilfe mit PHP.
    Also ich habe folgenden Code:

    PHP-Quellcode

    1. ​<meta charset="utf-8" class="__web-inspector-hide-shortcut__">
    2. <?php
    3. $text = 'Hallo Welt!';
    4. $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
    5. ', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$', '%', '&', '\'', '(', ')', '*', '+', '-', '.', ',', '/', ':', ';', '<', '>', '@', '=', '?', '[', ']', '{', '}', '~', '|', '_');
    6. $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", "!", "#", "$", "%", "&", "'", "(", ")", "*", "+", "-", ".", ",", "/", ":", ";", "<", ">", "@", "=", "?", "[", "]", "{", "}", "~", "|", "_");
    7. echo str_replace($normal, $wide, $text);
    8. ?>


    Kann halt den $text ausgeben so wie ich ihn will.
    Würde das ganze jetzt aber gerne erweitern sodass ich den Text in einer Textbox eingeben und sie in der anderen Textbox ausgegeben wird.

    Schon mal Danke für die Antworten!
    dein mainscript:

    PHP-Quellcode

    1. <?php
    2. if ($_POST) {
    3. $post = [
    4. 'input' => $_POST['input'],
    5. ];
    6. $ch = curl_init('<pfads zum replace.php-script>');
    7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    8. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    9. $response = curl_exec($ch);
    10. curl_close($ch);
    11. }
    12. ?>
    13. <form action="" method="POST">
    14. <input type="text" name="input"/>
    15. <input hidden value="<?php echo $_SERVER["SCRIPT_NAME"]; ?>" name="from"/>
    16. <input type="submit" value="ok"/>
    17. </form>
    18. <?php if ($_POST) : ?>
    19. <input type="text" name="output" value="<?php echo $response; ?>" />
    20. <?php endif; ?>



    dein replace.php

    PHP-Quellcode

    1. <?php
    2. $text = $_POST['input'];
    3. $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', '!', '#', '$', '%', '&', '\'', '(', ')', '*', '+', '-', '.', ',', '/', ':', ';', '<', '>', '@', '=', '?', '[', ']', '{', '}', '~', '|', '_');
    4. $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", "!", "#", "$", "%", "&", "'", "(", ")", "*", "+", "-", ".", ",", "/", ":", ";", "<", ">", "@", "=", "?", "[", "]", "{", "}", "~", "|", "_");
    5. echo str_replace($normal, $wide, $text);
    6. ?>


    beide im selben Verzeichnis, sollte funktionieren...
    Bin etwas in Eile, entschuldige wenn etwas nicht läuft.
    Für bessere Lösungen gerne kritisieren! :D

    LG Acr0most
    Wenn das Leben wirklich nur aus Nullen und Einsen besteht, dann laufen sicherlich genügen Nullen frei herum. :D
    Signature-Move 8o
    kein Problem mit privaten Konversationen zu Thema XY :thumbup:

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „Acr0most“ ()

    Gab leider einen Error:
    Parse error: syntax error, unexpected '[' in F:\Programs\xampp\htdocs\main.php on line 3

    Die Zeile

    PHP-Quellcode

    1. $post = ['input' => $_POST['input'],];


    und wenn ich die äußeren [] wegtue kommt das hier:
    Parse error: syntax error, unexpected T_DOUBLE_ARROW in F:\Programs\xampp\htdocs\main.php on line 3​

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „nikexo“ ()

    nikexo schrieb:

    $post = ['input' => $_POST['input'],];

    Ich bezweifle, dass hinter $_POST['input'] das "," gehört wenn in dem Array kein weiterer Eintrag ist.
    Weiß aber ned genau, ob das das Problem löst (arbeite nicht oft mit arrays).
    Programmierer aus Leidenschaft - Ich programmiere mit: HTML, CSS, JavaScript, PHP, Java (überwiegend Spigot- & Android-Entwicklung), C#(.NET-Framework) und Visual Basic(.NET-Framework)

    Felixprogram schrieb:


    Weiß aber ned genau, ob das das Problem löst (arbeite nicht oft mit arrays).


    Naja wie gesagt hab ja jetzt die [] entfernt:
    $post = 'input' => $_POST['input'];

    Mein Problem jetzt ist dieses:
    Parse error: syntax error, unexpected T_DOUBLE_ARROW in F:\Programs\xampp\htdocs\main.php on line 3
    das zusätzliche Komma sollte keinen stören...

    und ​$post = 'input' => $_POST['input']; muss in '[' ']' geschrieben werden, da du die Params als Array an den curl mitgeben musst.


    Wieso ist das bei dir Zeile 3?
    Poste doch mal deinen genauen Code.


    LG Acr0most
    Wenn das Leben wirklich nur aus Nullen und Einsen besteht, dann laufen sicherlich genügen Nullen frei herum. :D
    Signature-Move 8o
    kein Problem mit privaten Konversationen zu Thema XY :thumbup:

    Acr0most schrieb:


    Poste doch mal deinen genauen Code.


    main.php

    PHP-Quellcode

    1. <?php
    2. if ($_POST) {
    3. $post = array('input' => $_POST['input']);
    4. $ch = curl_init('replace.php');
    5. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    6. curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    7. $response = curl_exec($ch);
    8. curl_close($ch);
    9. }
    10. ?>
    11. <form action="" method="POST">
    12. <input type="text" name="input"/>
    13. <input hidden value="<?php echo $_SERVER["replace.php"]; ?>" name="from"/>
    14. <input type="submit" value="ok"/>
    15. </form>
    16. <?php if ($_POST) : ?>
    17. <input type="text" name="output" value="<?php echo $response; ?>" />
    18. <?php endif; ?>


    replace.php

    PHP-Quellcode

    1. <meta charset="utf-8" class="__web-inspector-hide-shortcut__">
    2. <?php
    3. $text = $_POST['input'];
    4. $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
    5. ', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$', '%', '&', '\'', '(', ')', '*', '+', '-', '.', ',', '/', ':', ';', '<', '>', '@', '=', '?', '[', ']', '{', '}', '~', '|', '_');
    6. $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", "!", "#", "$", "%", "&", "'", "(", ")", "*", "+", "-", ".", ",", "/", ":", ";", "<", ">", "@", "=", "?", "[", "]", "{", "}", "~", "|", "_");
    7. echo str_replace($normal, $wide, $text);
    8. ?>


    Fatal error: Call to undefined function curl_init() in F:\Programs\xampp\htdocs\main.php on line 4

    nikexo schrieb:

    Fatal error: Call to undefined function curl_init() in F:\Programs\xampp\htdocs\main.php on line 4



    Da ist offensichtlich die Curl-Extension noch nicht aktiviert/installiert.

    Gehe dazu wie hier beschrieben vor.

    Gib bitte Bescheid, ob der Fehler weiterhin kommt, ob es funzt oder andere Fehler auftreten.


    LG Acr0most
    Wenn das Leben wirklich nur aus Nullen und Einsen besteht, dann laufen sicherlich genügen Nullen frei herum. :D
    Signature-Move 8o
    kein Problem mit privaten Konversationen zu Thema XY :thumbup: