Jump to content

[SOLVED] What would be the alternative php placeholder for C++'s cin >> response >>endl;


Recommended Posts

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?

 

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

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!

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?

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.

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.