Created
March 19, 2018 05:15
-
-
Save ning415/c5380b2a5ad006d9e82334ee626ebfb9 to your computer and use it in GitHub Desktop.
cpe207-Basic Web Programming
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//echo ini_get('upload_max_filesize'); | |
phpinfo(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$next=1; | |
echo 'next number is '.$next++; | |
echo "<br>"; | |
$next=1; | |
echo 'next number is '.++$next; | |
echo "<br>"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#index array | |
$cars = array("Volvo", "BMW", "Toyota"); | |
echo 'I like '. $cars[0].' , '.$cars[1].' and '.$cars[2]; | |
echo '<br>'; | |
echo '<br>'; | |
$arrlength=count($cars); | |
for($x=0;$x<$arrlength;$x++) { | |
echo $cars[$x].'<br>'; | |
} | |
echo '<br>'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#assoc array | |
$age['Peter'] = 35; | |
$age['Ben'] = 43; | |
$age['Joe'] = 53; | |
echo 'Peter is ' . $age['Peter'].' years old.'; | |
echo '<br>';echo '<br>'; | |
foreach($age as $key=>$value) | |
{ | |
echo 'Key= '.$key. ' , Value= '.$value.'<br>'; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#multi array | |
$marks = array( | |
"john" => array ( | |
"course" => "physics", | |
"point" => 32 | |
), | |
"zara" => array ( | |
"course" => "physics", | |
"point" => 39 | |
) | |
); | |
echo '<pre>'; | |
print_r($marks); | |
echo '</pre>'; | |
echo '<br>'; | |
echo 'John get '. $marks['john']['point'] .' point in '. $marks['john']['course'] ; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#local variable | |
function assignx () { | |
$x = 0; | |
echo "$x inside function is $x. <br>"; | |
} | |
$x = 4; | |
assignx(); | |
echo "$x outside of function is $x. <br>"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#global variable | |
function addit() { | |
GLOBAL $somevar; | |
$somevar++; | |
echo "Somevar is $somevar <br>"; | |
} | |
$somevar = 15; | |
addit(); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
#static variable | |
function keep_track() { | |
STATIC $count = 0; | |
$count++; | |
echo 'count is '.$count.'<br>'; | |
} | |
$count=9; | |
keep_track(); // 1 | |
keep_track(); // 2 | |
keep_track(); // 3 | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "My heading "; | |
print "with style"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "<h1>My heading with style</h1><br>"; | |
print "<h2>My heading</h2>"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$month='March'; | |
echo 'current variable type is <b>'.gettype($month) . "</b><br>"; | |
$month=3; | |
echo 'new variable type is <b>'.gettype($month) . "</b><br>"; | |
$month="3"; | |
echo "month \'s value is $month , variable type is <b>".gettype($month) . "</b><br>"; | |
$monthId=(int)$month; | |
echo "monthId \'s value is $monthId , variable type is <b>".gettype($monthId) . "</b><br>"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$a = 'hello'; | |
$$a = 'world'; | |
echo "$a $hello"; | |
echo '<br>'; | |
${'a' . 'b'} = 'hello there'; | |
echo $ab; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('FRUIT','apple',true); | |
ECHO FRUIT; | |
echo '<br>'; | |
ECHO fruit; | |
echo '<br>'; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo "This line number is : " .__LINE__; | |
echo "<br>"; | |
echo "The full path of this file is: " . __FILE__; | |
echo "<br>"; | |
echo dirname(__FILE__); | |
echo "<br>"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$variable='data';// \'s value | |
echo 'My $variable will not print'; | |
echo "<br>"; | |
echo "My $variable will print"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x=100; | |
$y='100'; | |
if($x===$y) | |
echo 'equal'; | |
else | |
echo 'not equal'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment