php入门操作

时间:2022-05-06
本文章向大家介绍php入门操作,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
<?php

/**
 * @author minguanghui
 * @copyright 2012
 */
$str="Hello everyone!<br>";
$i=6;
$string="morning everybody!<br>";
print($str);
print("ÄãºÃ£¡<br>");
print($string);
echo($i);
echo $i;
/*
if else ÅжÏ
*/
$d=date("Mon");
print $d;
print "<br>";
if($d=="Fri")
    echo "Have a nice weekend!<br>";
elseif($d=="Mon")
    echo "Today is Monday!<br>";
else
    echo "Today is not Friday!<br>";
print "good!";

/*
switch
*/
print "<br>";
$x=3;
switch($x){
    case 1:
        echo "Number 1.";
        break;
    case 2:
        echo "Number 2.";
        break;
    case 3:
        echo "Number 3.";
        break;
    default:
        echo "There is no number.";
}

/*
Êý×é
*/
print "<br>";
$names=array("aaa","bbb","ccc","ddd");
echo $names[0]." and ".$names[1]." is ".$names[2]."'s neighber.";

/*
while
*/
print "<br>";
$x=0;
while($x<100){
    echo $x." ";
    $x++;
}

/*
for
*/
print "<br>";
for($i=0;$i<100;$i++){
    echo $i." ";
}

/*
foreach
*/
print "<br>";
$array=array("one","two","three","four","five");
$length=count($array);
for($i=0;$i<$length;$i++){
    print $array[$i]." ";
}
print "<br>";
foreach($array as $values){
    print $values." ";
}

/*
function
*/
print "<br>";
function printName(){
    echo "Your name.";
}
printName();

function printString($m){
    for($i=0;$i<$m;$i++){
        print $i." ";
    }
}
printString(100);

print "<br>";
function add($i, $j){
    return $i+$j;
}
echo add(3,4);

/*
date
*/
print "<br>";
echo date("Y/m/d");
echo "<br>".date("Y.m.d");
echo "<br>".date("Y-m-d");
$date=date("now");
echo "<br>".$date;

/*
file
*/
print "<br>";
$file=fopen("E:\test.txt","r") or exit("The file is not exit.");
while(!feof($file)){
    echo fgets($file)."<br>";
}
fclose($file);

$file=fopen("E:\test.txt","r") or exit("The file is not exit.");
while(!feof($file)){
    echo fgetc($file);
}
fclose($file);

print "<br>";
$a=56;
echo gettype($a)."<br>";
$a=2342314.233242;
echo gettype($a)."<br>";
settype($a,'boolean');
echo gettype($a)."<br>";
echo is_double($a);
echo isset($a)."<br>";
echo isset($b);
echo empty($a)."<br>";
echo empty($c)."<br>";




/*
phpÊäÈë
*/
/*
$s=fgets($stdin);
echo "The input is {$s}";
?>
<script Language="JavaScript">
function ctlent(eventobject)
{
if(event.ctrlKey && window.event.keyCode==13)
{
this.document.frmAnnounce.submit();
}
}
}
</script>
<form action="" method=POST name=frmAnnounce>
<textarea class=smallarea cols=95 name=Content rows=12 wrap=VIRTUAL title=¿ÉÒÔʹÓÃCtrl+EnterÖ±½ÓÌá½»Ìù×Ó class=FormClass onkeydown=ctlent()></textarea>
</form>
*/