Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Community > MacNN Lounge > Anyone knows php here?

Anyone knows php here?
Thread Tools
Mac Elite
Join Date: Dec 2000
Location: Tempe, AZ
Status: Offline
Reply With Quote
Jul 25, 2005, 08:30 PM
 
I am stuck on the following... I would like to get some text from a user and then input that as a variable.

$a = "$input";

If the user types a word starting with a dollar sign ($), I get an error, saying that the variable does not exist... Any ideas on how to filter the dollar sign out?

Thanks,

dombi
     
Addicted to MacNN
Join Date: May 2001
Status: Offline
Reply With Quote
Jul 25, 2005, 11:49 PM
 
Um... try:

$a = $input;
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
     
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status: Offline
Reply With Quote
Jul 26, 2005, 12:05 AM
 
$a = $input; will just set a variable called $a to the same value as a variable named $input, it won't actually get the input from the user.

How are they inputing the information? Is it a web form, or just at the terminal?

If it's a web form, then the information they enter will be stored in either $_GET or $_POST depending on the submission method you're using. So if the input box was named "foo" on the web form, you would do $a = $_GET["foo"] or $a = $_POST["foo"].

If it's at the terminal... I'm not actually sure. Why would you use PHP at the terminal?
     
Baninated
Join Date: Dec 2004
Location: Illinois might be cold and flat, but at least it's ugly.
Status: Offline
Reply With Quote
Jul 26, 2005, 12:24 AM
 
Where does he mention 'terminal'?

$name = $_GET["Name"]
$name = $_POST["Name"]

Is correct, but $a is a bad variable, can't you come up with something more understandable?
     
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status: Offline
Reply With Quote
Jul 26, 2005, 12:27 AM
 
Originally Posted by budster101
Where does he mention 'terminal'?

$name = $_GET["Name"]
$name = $_POST["Name"]

Is correct, but $a is a bad variable, can't you come up with something more understandable?
He didn't say anything about the terminal, but he also didn't say anything that would make me think it was for a web page. So I figured I'd cover all the bases as best I can. As his sig says he's a web designer and PHP isn't a language that most people would choose for programming outside a web environment I wasn't too worried that I had no idea how to get input from the command line in PHP.

And $a was his variable name not mine. I was just using his example.
     
Baninated
Join Date: Dec 2004
Location: Illinois might be cold and flat, but at least it's ugly.
Status: Offline
Reply With Quote
Jul 26, 2005, 12:32 AM
 
I know about the variable name, I think I should have been clearer in my response, and I actually was directing it towards him. Sorry for the confusion, I was not critiquing your code.

Right about the web / php... conclusion.
     
Professional Poster
Join Date: Oct 2001
Location: London
Status: Offline
Reply With Quote
Jul 26, 2005, 02:04 AM
 
Yeah - the lounge - *great* place to post PHP questions.

The webDev forum must be for posting stories about badgers and things.
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Jul 26, 2005, 02:29 AM
 
Better than what's usually posted in the lounge.
     
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status: Offline
Reply With Quote
Jul 26, 2005, 02:44 AM
 
And amazingly, this thread has yet to see any use of the "Ha! Ha!" picture.
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
     
Addicted to MacNN
Join Date: May 2001
Status: Offline
Reply With Quote
Jul 26, 2005, 03:30 AM
 
Um.. original question is:

"If the user types a word starting with a dollar sign ($), I get an error, saying that the variable does not exist... Any ideas on how to filter the dollar sign out?"

Not how you read in the user's input.
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
     
Addicted to MacNN
Join Date: May 2001
Status: Offline
Reply With Quote
Jul 26, 2005, 03:35 AM
 
If the question was how to you get the user input, then I would have to ask how is the user inputting data.

Is the coming from command line?
From a web form? GET or POST method?
What's for form field name?
Is global variables turned on?
Bush Tax Cuts == Job Killer
June 2001: 132,047,000 employed
June 2003: 129,839,000 employed
2.21 million jobs were LOST after 2 years of Bush Tax Cuts.
     
Grizzled Veteran
Join Date: Jun 2002
Location: Probably some pub in Reykjavik
Status: Offline
Reply With Quote
Jul 26, 2005, 05:16 AM
 
BAH!

Use WebObjects, it's free now. And drag'n'drop is just so much more fun



(I know - not much help, but one has to spread the good word, right?)
(Last edited by Hugi; Jul 26, 2005 at 06:26 AM. )
     
Mac Elite
Join Date: Apr 2002
Location: Illinois
Status: Offline
Reply With Quote
Jul 26, 2005, 06:22 AM
 
well, there is always the good ol eregi_replace...
eregi_replace("\$", "", $input);
not sure if that's gonna do it for you, but it should.
     
Posting Junkie
Join Date: Jun 2001
Location: Washington DC
Status: Offline
Reply With Quote
Jul 26, 2005, 03:15 PM
 
Originally Posted by budster101
I know about the variable name, I think I should have been clearer in my response, and I actually was directing it towards him. Sorry for the confusion, I was not critiquing your code.

Right about the web / php... conclusion.
Ah, whoops. Sorry bout that.
     
Baninated
Join Date: Dec 2004
Location: Illinois might be cold and flat, but at least it's ugly.
Status: Offline
Reply With Quote
Jul 26, 2005, 03:56 PM
 
That's cool. A lot of us are not very quick these days, and I've missed a few admittedly and have had to have a bit of crow myself.

     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 04:43 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2