patawic Posted February 2, 2010 Share Posted February 2, 2010 I am currently creating a fake Command prompt for a website but i am stuck. http://xboxgamercard.net/cmd/ If i insert 1 message it shows this But if i insert a second message it merges the 2 messages together I need to make it so that on the second message it doesnt say ''test' test' but so it only says 'test' Heres the code im using too submit it. <?php $msg = $_GET['text']; $msg = str_replace("Microsoft Windows [Version 6.1.7600]", "", $msg); $msg = str_replace("Copyright (c) 2009 Microsoft Corporation. All rights reserved.", "", $msg); $msg = str_replace("is not recognized as an internal or external command,operable program or batch file.", "", $msg); $msg = str_replace("\\", "", $msg); $msg = str_replace("C:WINDOWS>", "", $msg); $msg2 = " '$msg' is not recognized as an internal or external command, operable program or batch file. C:\WINDOWS>"; $fn = "text.txt"; $file = fopen($fn, "a"); fwrite($file, "$msg2"); fclose($file); ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 2, 2010 Share Posted February 2, 2010 You will never be able to determine the "new" input using regular expression. You can probably come close, but I would juse use an index value on each submission. The following code is modified from your to just use a form instead of writing to a file as I don't know how you were using it for display. But, this shoudl get you in the right direction. <?php function stripslashes_deep($value) { $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value); return $value; } if (get_magic_quotes_gpc()) { $_GET = stripslashes_deep($_GET); } if (!isset($_GET['idx'])) { $idx = 115; $text = "Microsoft Windows [Version 6.1.7600]\n"; $text .= "Copyright (c) 2009 Microsoft Corporation. All rights reserved.\n"; } else { $idx = $_GET['idx'] + 3; $input = $_GET['text']; $text = substr($input, 0, $idx); $user_input = substr($input, $idx); $text .= "\n'{$user_input}' is not recognized as an internal or external command,\noperable program or batch file.\n"; } $text .= "\n"; $text .= "C:WINDOWS>"; $idx = strlen($text); //echo strlen($text); //$fn = "text.txt"; //$file = fopen($fn, "a"); //fwrite($file, "$msg2"); //fclose($file); ?> <html> <style> body{ background-color:#000000;color:#ffffff } textarea { background-color:#000000; color:#ffffff; width:100%; height:400px; } </style> <body> <form method="GET"> <textarea name="text"><?php echo $text; ?></textarea> <input type="text" name="idx" value="<?php echo $idx; ?>"> <button type="submit" name="submit">Submit</button> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
teamatomic Posted February 2, 2010 Share Posted February 2, 2010 I ran your code twice replacing the POST with $msg='xxxxxxxxxxxxxxxxxxxxxxxxx'; This is what I got. 'xxxxxxxxxxxxxxxxxx' is not recognized as an internal or external command, operable program or batch file. C:\WINDOWS> 'xxxxxxxxxxxxxxxxxx' is not recognized as an internal or external command, operable program or batch file. C:\WINDOWS> 'xxxxxxxxxxxxxxxxxx' is not recognized as an internal or external command, operable program or batch file. C:\WINDOWS> Maybe if you showed the form as the code seems to do what it should. Where does the form data come from? HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
patawic Posted February 2, 2010 Author Share Posted February 2, 2010 it comes from the textarea on the main page. and is submitted by a javascript code. The reason it was working properly was because it wasnt submitting the whole of the textarea. if you do the same thing in the textarea the error message will stack up EDIT: At mjdamato I have to use a textarea. your code just uses an input box. as my javascript code grabs the messages from the .txt file, and places them as the value of the textarea Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 2, 2010 Share Posted February 2, 2010 EDIT: At mjdamato I have to use a textarea. your code just uses an input box. as my javascript code grabs the messages from the .txt file, and places them as the value of the textarea Oh really!? What is that first tag after the FORM tag? <form method="GET"> <textarea name="text"><?php echo $text; ?></textarea> <input type="text" name="idx" value="<?php echo $idx; ?>"> <button type="submit" name="submit">Submit</button> </form> You didn't provide ALL of the relevant code for your project - so I winged it as best I could. The code I provided does work - at least how I interpreted your requirements. Did you even try the code I posted? It is a completely self-contained script that you can run. If it seems to work how you want, you can then repupose it with slight modifications to your exisitng code. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.