Hello.

Help me find an error in the code.

There are two text fields. When you enter a certain word in the first field and press enter, the source word should be replaced with a new one in the second text field.

On this code

<? $b = ''; if(isset($_POST['a'])){ $b = $_POST['a']; } ?> <? $s = $b $s = str_replace("ΠΏΡ€ΠΈΠ²Π΅Ρ‚", "ΠΏΠΎΠΊΠ°"); $b = $s ?> <html> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> <body> <br> Π’ ΠΏΠ΅Ρ€Π²ΠΎΠ΅ тСкстовоС ΠΏΠΎΠ»Π΅ Π²Π²Π΅Π΄ΠΈΡ‚Π΅ запрос. НаТмитС ΠΊΠ½ΠΎΠΏΠΊΡƒ "ΠΎΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ". <br><br> <form method="post"> <input type='text' size="100" name='a'><br> <input type='text' size="100" name='b' value='<?=$b?>'> <input type='submit' value="ΠžΡ‚ΠΏΡ€Π°Π²ΠΈΡ‚ΡŒ"> </form> </body> </html> 

an error is displayed

 "Parse error: syntax error, unexpected '$s' (T_VARIABLE) in ...test.php on line 11. 

11 line is the code "$ s = str_replace (" hello "," bye "));"

Tried another code to use:

replaced this code

 $s = str_replace("ΠΏΡ€ΠΈΠ²Π΅Ρ‚", "ΠΏΠΎΠΊΠ°"); 

on

 if (strpos($s, 'ΠΏΡ€ΠΈΠ²Π΅Ρ‚') !== false) { $s = str_replace("ΠΏΡ€ΠΈΠ²Π΅Ρ‚", "ΠΏΠΎΠΊΠ°", $s); } 

Displays the error "Parse error: syntax error, unexpected 'if' (T_IF) in ... test.php on line 11"

11 line is "if (strpos ($ s, 'hello')! == false) {"

Where did I make a mistake?

  • you; losing for example, here $ s = $ b and in other places, too, so he curses. and replays are not in the business. don't cut it, they are needed here - vitidev
  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky ♦

2 answers 2

Correctly writes, there is no third parameter: str_replace ("what are we looking for", "what are we changing for", "where")

 $s = str_replace("ΠΏΡ€ΠΈΠ²Π΅Ρ‚", "ΠΏΠΎΠΊΠ°", $s); 
  • Well, do not forget the semicolon - x64

If you add a semicolon and the third parameter, then everything works fine in Opera 12.17 browser. And in IE 11 and in the browser Vivaldi Cyrillic is not displayed, and the replacement does not occur.