Modernvox Posted November 4, 2009 Share Posted November 4, 2009 I really think C++ is easier to learn... string word1; string word2; cout << "Guess a word?: "; cin >> word1; cout << word1; Maybe I've gotten so use to the cout and cin functions of C++ Can you perform the same example using PHP for me? Quote Link to comment Share on other sites More sharing options...
Alex Posted November 4, 2009 Share Posted November 4, 2009 You're talking about PHP CLI right? echo "Guess a word?:"; $word = fread(STDIN, 80); echo $word; Quote Link to comment Share on other sites More sharing options...
Garethp Posted November 4, 2009 Share Posted November 4, 2009 Um... PHP doesn't have a cin function. You'd need something else. Like this <?php echo "<form action=\"\" method=\"post\"> Guess a Word?: <input type=\"text\" name=\"word1\"><br> <input type=\"submit\" value=\"Guess\">"; if(isset($_POST['word1'])) { $word1 = $_POST['word1']; $word2; echo "<br><br>" . $word1; } ?> See, PHP only runs once, so you need to give it the input before you run it. That code gives you a form to enter the input, and once you input it, it sends the input to itself, and checks if the input exists, if so, display it Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 4, 2009 Author Share Posted November 4, 2009 You're talking about PHP CLI right? echo "Guess a word?:"; $word = fread(STDIN, 80); echo $word; CLI? Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 4, 2009 Author Share Posted November 4, 2009 Um... PHP doesn't have a cin function. You'd need something else. Like this <?php echo "<form action=\"\" method=\"post\"> Guess a Word?: <input type=\"text\" name=\"word1\"><br> <input type=\"submit\" value=\"Guess\">"; if(isset($_POST['word1'])) { $word1 = $_POST['word1']; $word2; echo "<br><br>" . $word1; } ?> See, PHP only runs once, so you need to give it the input before you run it. That code gives you a form to enter the input, and once you input it, it sends the input to itself, and checks if the input exists, if so, display it Create a form just for that? That stinks! Quote Link to comment Share on other sites More sharing options...
Alex Posted November 4, 2009 Share Posted November 4, 2009 PHP CLI is running PHP from the command line. You can also compile PHP into stand-alone executables though. Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 4, 2009 Author Share Posted November 4, 2009 PHP CLI is running PHP from the command line. You can also compile PHP into stand-alone executables though. Ok. Yeah, your example seems relatively easy, but what does the 80 mean? Is that a port? Quote Link to comment Share on other sites More sharing options...
Alex Posted November 4, 2009 Share Posted November 4, 2009 fread(). 80 is the length (in bytes) to read. Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted November 4, 2009 Share Posted November 4, 2009 you have to understand that PHP isn't the same as C++. Input (generally) comes from some sort of HTML form. Like Alex said, PHP does have support for command line input (the equivalent of cin) but generally, this isn't used, as PHP is mostly used for web applications. You can make desktop applications with PHP (assuming you have the interpreter on your computer/server) but PHP really shines when using it for websites. As far as ease of use, I find PHP much easier to use than C++, especially because all of PHP's different libraries can be used once they are installed without having to include header files every time. However, C++ is an incredibly powerful language. Really, picking a language is all about the task at hand. For a desktop application, C++ is definitely the winner, however PHP is much "better" with web applications. By better, I don't necessarily mean more efficient, but easier to use, and more geared towards web applications. Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 4, 2009 Author Share Posted November 4, 2009 fread(). 80 is the length (in bytes) to read. Thanks Quote Link to comment Share on other sites More sharing options...
Modernvox Posted November 4, 2009 Author Share Posted November 4, 2009 you have to understand that PHP isn't the same as C++. Input (generally) comes from some sort of HTML form. Like Alex said, PHP does have support for command line input (the equivalent of cin) but generally, this isn't used, as PHP is mostly used for web applications. You can make desktop applications with PHP (assuming you have the interpreter on your computer/server) but PHP really shines when using it for websites. As far as ease of use, I find PHP much easier to use than C++, especially because all of PHP's different libraries can be used once they are installed without having to include header files every time. However, C++ is an incredibly powerful language. Really, picking a language is all about the task at hand. For a desktop application, C++ is definitely the winner, however PHP is much "better" with web applications. By better, I don't necessarily mean more efficient, but easier to use, and more geared towards web applications. I gotta check if I have all the lib's. I really like the flow of C++ where i find php has some weird rules such as double quotes around variables and single quotes around raw text. Things like this confuse the hell out of me. Well put though! 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.