PHP Help

Status
Not open for further replies.

ummdav1d

New member
Dec 15, 2007
84
0
0
I have this:

<?php if ($_GET[’kw’])
{echo ucwords($_GET[’kw’]);}
else
{echo ucwords(”Your Original Info Here”);}?>

and I get this: Parse error: syntax error, unexpected T_STRING in /home/winschol/public_html/greatcarrates/index.php on line 9

ideas?
 


1. your code does not even have 9 lines, so no error on line 9 probably
1. the code works ok to me
3. use code tags next time
4. never talk about rule nr. 1
 
Try this:
PHP:
<? php
 if(isset($_GET['kw'])){
        echo ucwords($_GET[’kw’]);
        }
        else{
         echo ucwords(”Your Original Info Here”);   
        }
?>


Your echo statements do not look right to me, but not sure.
 
Try this:
PHP:
<? php
 if(isset($_GET['kw'])){
        echo ucwords($_GET[’kw’]);
        }
        else{
         echo ucwords(”Your Original Info Here”);   
        }
?>


Your echo statements do not look right to me, but not sure.

never use isset() - always use empty() or if it should be a number in the var use is_numeric().

so its
PHP:
<?php

$_GET['kw'] = trim( urldecode( $_GET['kw'] ) );
if( !empty( $_GET['kw'] ) ) {
     echo ucwords( $_GET['kw'] );
} else echo 'no keyword given';

?>

another way to set a var would be:
PHP:
<?php
$_GET['kw'] = trim( urldecode( $_GET['kw'] ) );
$keyword = ( !empty( $_GET['kw'] ) ) ? ucwords( $_GET['kw'] ) : 'no keyword given';
?>
 
never use isset() - always use empty() or if it should be a number in the var use is_numeric().

so its
PHP:
<?php

$_GET['kw'] = trim( urldecode( $_GET['kw'] ) );
if( !empty( $_GET['kw'] ) ) {
     echo ucwords( $_GET['kw'] );
} else echo 'no keyword given';

?>
another way to set a var would be:
PHP:
<?php
$_GET['kw'] = trim( urldecode( $_GET['kw'] ) );
$keyword = ( !empty( $_GET['kw'] ) ) ? ucwords( $_GET['kw'] ) : 'no keyword given';
?>

Hey Tobsn, I've heard you are an excellent php programmer, do you have any resources to suggest as far as best practices for php?
 
How come no isset()?

is set returns true even if there is nothing in it because it tests if the variable IS SET not if anything is in it ;)

try it
domain.com/bla.php?var=

isset( $_GET['var'] ) should return true, even if there is nothing in it - because the var "is set" ;)

got it? :p
 
Hey Tobsn, I've heard you are an excellent php programmer, do you have any resources to suggest as far as best practices for php?

test around and read the comments in the PHP: Hypertext Preprocessor documentation.
for example: i've never read a book about php but i would say im a very advanced coder.
the only book i've ever read that is related to a programming language was a book about coding patterns and the MVC model.

so my suggestion is that you just try out what is possible, read the comments to get new ideas and better solutions for your code. just try to build scrapers for login required sites ;)
helps a lot to get a feeling for the http protocol.
 
is set returns true even if there is nothing in it because it tests if the variable IS SET not if anything is in it ;)

try it
domain.com/bla.php?var=

isset( $_GET['var'] ) should return true, even if there is nothing in it - because the var "is set" ;)

got it? :p

That makes complete sense. Never thought about that way, I've only used to to see if I've typed the captcha yet.

Thanks for explaining it.
 
Also, the PHP color parser here looks like crap. Lots of non-contrasty colors. I have to select it to read it.
 
Status
Not open for further replies.