orange gold Posted September 26, 2007 Share Posted September 26, 2007 hey, i finally decided to give php a chance... ive been in actionscript all my life... i know some html and java but anyways... ... can anyone here give me examples of basic code that is good to know and teach me something about php so i can start learning or give me some links to good beginers tuts. thankyou! in otherwords... im a noob who knows nuthing about php and need help, tell me some basics, thanks Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/ Share on other sites More sharing options...
clookid Posted September 26, 2007 Share Posted September 26, 2007 <?php - Opening tag for PHP (long-hand). <? - Opening tag for PHP (short-hand). ?> - Closing tag for PHP. echo "Hello world!"; - This will output "Hello world!". The echo statement can be used to display various arrays, functions etc. HTML can also be embedded in an echo statement, replace any double-quotes that HTML would use with single-quotes. print "Hello world!"; - The print statement is almost identical to the echo statement. $foo = "Billy"; echo "My name is $foo."; - This echo statement will output "My name is Billy.". It makes use of a variable. $array['0'] = "Billy"; $array['1'] = "Sally"; echo "My name is $array['0'], my sister's name is $array['1']."; - This echo statement will output "My name is Billy, my sister's name is Sally.". It makes use of variable arrays ($array[key]). If you are still interested in learning some more PHP, feel free to wander over to http://www.tizag.com to pick up some more basic knowledge. If you would like to learn how to use more advanced PHP, wander over to http://www.php.net and take a look at the manual. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/#findComment-355399 Share on other sites More sharing options...
marcus Posted September 26, 2007 Share Posted September 26, 2007 Commenting <?php //this is a comment # this is also a comment /* this is also a comment */ ?> Requesting <?php $variable_get = $_GET['variable']; //requesting url configuration: index.php?variable=value $variable_post = $_POST['variable']; //requesting form configuration, sent by form method post $variable_req = $_REQUEST['variable']; //requesting from both get/post, will find one, and use that one $variable_ses = $_SESSION['variable']; //session variable, define by $_SESSION['variable'] = "value"; $variable_coo = $_COOKIE['variable']; //cookie variable, define by using setcookie(); $variable_ser = $_SERVER['REMOTE_ADDR']; //will return user's IP using the server request method ?> Arrays <?php $array = array(); //array with no values $array[] = "value1"; //will set the 0 key to the $array variable $array2 = array('value1','value2','value3'); //array with 3 true values ?> Echo/Print Difference between the two: Even though print() and echo() are essentially interchangeable most of the time, there is a substantial difference between them. While print() behaves like a function with its own return value (although it is a language construct), echo() is actually a language construct that has no return value and cannot, therefore, be used in an expression. Using Echo/Print <?php echo constant; //will echo constant unless constant is defined echo "string"; //will echo string with usage of double quotes echo 'string'; //also a string using single quotes echo $variable; //will echo the value of the variable $variable //print print constant; //will print constant unless constant is defined print "string"; //same print 'string'; //same print $variable; //same ?> Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/#findComment-355401 Share on other sites More sharing options...
orange gold Posted September 26, 2007 Author Share Posted September 26, 2007 ok i learned all that thanks, now im out to learn more anything else you guys wana throw at me??? Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/#findComment-355407 Share on other sites More sharing options...
marcus Posted September 26, 2007 Share Posted September 26, 2007 <?php $string = "i|like|using|explode|to|show|every|single|partical|of|text|in|this|string"; $boom = explode("|",$string); foreach($boom AS $explosions){ echo $explosions . "<br />\n"; } ?> exploding shit is fun Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/#findComment-355409 Share on other sites More sharing options...
orange gold Posted September 26, 2007 Author Share Posted September 26, 2007 ok i wanted to knwo is there an easier way to make two echo lines break so instead of saying... my name is billy. you name isnt billy it will say... my name is billy. you name isnt billy. this is the code ive got so far <?php $foo = "billy"; echo "My name is $foo."; echo "<br>"; echo "you name isnt $foo"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/#findComment-355410 Share on other sites More sharing options...
rlindauer Posted September 26, 2007 Share Posted September 26, 2007 <?php $string = "i|like|using|explode|to|show|every|single|partical|of|text|in|this|string"; $boom = explode("|",$string); foreach($boom AS $explosions){ echo $explosions . "<br />\n"; } ?> exploding shit is fun Hell yeah it is ok i wanted to knwo is there an easier way to make two echo lines break so instead of saying... my name is billy. you name isnt billy it will say... my name is billy. you name isnt billy. this is the code ive got so far <?php $foo = "billy"; echo "My name is $foo."; echo "<br>"; echo "you name isnt $foo"; ?> <?php $foo = "billy"; echo "My name is $foo.<br>you name isnt $foo"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/#findComment-355425 Share on other sites More sharing options...
orange gold Posted September 26, 2007 Author Share Posted September 26, 2007 ok i got all that... anything elese you guys wana throw at me Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/#findComment-355585 Share on other sites More sharing options...
HuggieBear Posted September 26, 2007 Share Posted September 26, 2007 ok i got all that... anything elese you guys wana throw at me Nope, you're an expert now ;-) Try some of the tutorials here @ PHPFreaks Regards Huggie Quote Link to comment https://forums.phpfreaks.com/topic/70701-im-a-noob-help-me-with-basics/#findComment-355593 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.