php学习(一)
Jun 23, 2016 pm 02:34 PM
<?php //写cookiesetcookie("user", "wang70937", time()+60);//sessionsession_start();if(isset($_SESSION['views'])) $_SESSION['views']=$_SESSION['views']+1;else $_SESSION['views']=1;echo "Session: Views=". $_SESSION['views']."<br />";?><script > function Show(){ alert("asdf"); }</script><html> <title>php测试页面 </title> <head><script src="clienthint.js"></script></head> <body> <?php //输出 echo "<br />"."[******输出******]"."<br />"; echo "Hello World!"."<br />"; $a = "Php"; $b = "Language"; echo $a." ".$b."<br />"; //数组 echo "<br />"."[******数组******]"."<br />"; $arr = array("abcde", "fghijk", "lmnopq"); foreach($arr as $value) { echo $value."<br />"; } //函数 echo "<br />"."[******函数******]"."<br />"; function FunA($A, $B){ echo "函数参数:".$A.", ".$B; return "ret_value"; } $ret = FunA(123, "param"); echo "函数返回值:".$ret."<br />"; echo "<br />"."[******表单******]"."<br />"; ?> <form action="form.php" method="post"> Name: <input type="text" name="name" /> Age: <input type="text" name="age" /> <input type="submit" /> </form> <?php echo "<br />"; echo "<br />"."[******上传文件******]"."<br />"; ?> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> <?php //session echo "<br />"."[******session******]"."<br />"; //retrieve session data echo "Pageviews=". $_SESSION['views']; ?> <br /> <!-- //删除session --> <?php //echo "<br />"."[******删除session******]"."<br />"; // session_destroy(); ?> <?php //发送邮件 echo "<br />"."[******发送邮件******]"."<br />"; $to = "wang70937@163.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "wang70937@gmail.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."."<br />"; ?> <?php //mysql数据库 echo "<br />"."[******mysql数据库******]"."<br />"; $con = mysql_connect("localhost","root","1"); if (!$con) { die('Could not connect: ' . mysql_error()); } else echo "连接Mysql成功!"."<br />"; mysql_select_db("bbs", $con); mysql_query("set names GBK"); //show tables $TableCount = mysql_query("show tables"); while($Table = mysql_fetch_array($TableCount)) { //表名 $TableName = $Table[0]; $sql = "select * from ".$TableName; $result = mysql_query($sql); echo "<br />表:[".$TableName."]<br />"; //表的字段个数 $FiledCount = mysql_num_fields($result); //记录条数 $RecordCount = mysql_num_rows($result); echo "sql[".$sql."] 记录条数:".$RecordCount."<br />"; if($FiledCount > 0 ) { echo "<table border='1'>; <tr> <th>记录序号</th>"; for($index=0; $index<$FiledCount; $index++) { //字段名 $FiledName = mysql_fetch_field($result); echo "<th>$FiledName->name</th>"; } echo "</tr>"; $No = 0; while($row = mysql_fetch_array($result)) { $No = $No + 1; echo "<tr>"; echo "<td>" . $No . "</td>"; for($index=0; $index<$FiledCount; $index++) { echo "<td>" . $row[$index] . "</td>"; } echo "</tr>"; } echo "</table>"; } } mysql_close($con); ?> <?php //xml解析 echo "<br />"."********xml解析********"."<br />"; /*$xmlDoc = new DOMDocument(); $xmlDoc->load("note.xml"); $x = $xmlDoc->documentElement; foreach ($x->childNodes AS $item) { print $item->nodeName . " = " . $item->nodeValue . "<br />"; }*/ $xml = simplexml_load_file("note.xml"); echo $xml->getName() . "<br />"; foreach($xml->children() as $child) { echo $child->getName() . ": " . $child . "<br />"; } ?> <?php //ajax echo "<br />"."*******ajax*******"."<br />"; ?> <form> First Name: <input type="text" id="txt1" //onkeyup="showHint(this.value)" onkeyup="Show()"> </form> <p>Suggestions: <span id="txtHint"></span></p> </body> </html>
Copy after login
<p class="sycode"> 1 <? php 2 // 写cookie 3 setcookie ( " user " , " wang70937 " , time () + 60 ); 4 // session 5 session_start (); 6 7 if ( isset ( $_SESSION [ ' views ' ])) 8 $_SESSION [ ' views ' ] = $_SESSION [ ' views ' ] + 1 ; 9 10 else 11 $_SESSION [ ' views ' ] = 1 ; 12 echo " Session: Views= " . $_SESSION [ ' views ' ] . " <br /> " ; 13 ?> 14 15 < script > 16 function Show(){ 17 alert( " asdf " ); 18 } 19 </ script > 20 21 < html > 22 < title > php测试页面 </ title > 23 < head >< script src = " clienthint.js " ></ script ></ head > 24 < body > 25 <? php 26 // 输出 27 echo " <br /> " . " [******输出******] " . " <br /> " ; 28 echo " Hello World! " . " <br /> " ; 29 $a = " Php " ; 30 $b = " Language " ; 31 echo $a . " " . $b . " <br /> " ; 32 33 // 数组 34 echo " <br /> " . " [******数组******] " . " <br /> " ; 35 $arr = array ( " abcde " , " fghijk " , " lmnopq " ); 36 foreach ( $arr as $value ) 37 { 38 echo $value . " <br /> " ; 39 } 40 41 // 函数 42 echo " <br /> " . " [******函数******] " . " <br /> " ; 43 function FunA( $A , $B ){ 44 echo " 函数参数: " . $A . " , " . $B ; 45 return " ret_value " ; 46 } 47 $ret = FunA( 123 , " param " ); 48 echo " 函数返回值: " . $ret . " <br /> " ; 49 50 51 echo " <br /> " . " [******表单******] " . " <br /> " ; 52 ?> 53 < form action = " form.php " method = " post " > 54 Name : < input type = " text " name = " name " /> 55 Age : < input type = " text " name = " age " /> 56 < input type = " submit " /> 57 </ form > 58 59 <? php echo " <br /> " ; 60 61 echo " <br /> " . " [******上传文件******] " . " <br /> " ; 62 ?> 63 < form action = " upload_file.php " method = " post " 64 enctype = " multipart/form-data " > 65 < label for = " file " > Filename :</ label > 66 < input type = " file " name = " file " id = " file " /> 67 < br /> 68 < input type = " submit " name = " submit " value = " Submit " /> 69 </ form > 70 71 <? php 72 // session 73 echo " <br /> " . " [******session******] " . " <br /> " ; 74 75 // retrieve session data 76 echo " Pageviews= " . $_SESSION [ ' views ' ]; 77 ?> 78 < br /> 79 80 <!-- // 删除session --> 81 <? php 82 // echo "<br />"."[******删除session******]"."<br />"; 83 // session_destroy(); 84 ?> 85 86 <? php 87 // 发送邮件 88 echo " <br /> " . " [******发送邮件******] " . " <br /> " ; 89 90 $to = " wang70937@163.com " ; 91 $subject = " Test mail " ; 92 $message = " Hello! This is a simple email message. " ; 93 $from = " wang70937@gmail.com " ; 94 $headers = " From: $from " ; 95 mail ( $to , $subject , $message , $headers ); 96 echo " Mail Sent. " . " <br /> " ; 97 ?> 98 99 <? php 100 // mysql数据库 101 echo " <br /> " . " [******mysql数据库******] " . " <br /> " ; 102 $con = mysql_connect ( " localhost " , " root " , " 1 " ); 103 if ( ! $con ) 104 { 105 die ( ' Could not connect: ' . mysql_error ()); 106 } 107 else 108 echo " 连接Mysql成功! " . " <br /> " ; 109 mysql_select_db ( " bbs " , $con ); 110 mysql_query ( " set names GBK " ); 111 // show tables 112 $TableCount = mysql_query ( " show tables " ); 113 while ( $Table = mysql_fetch_array ( $TableCount )) 114 { 115 // 表名 116 $TableName = $Table [ 0 ]; 117 $sql = " select * from " . $TableName ; 118 $result = mysql_query ( $sql ); 119 120 echo " <br />表:[ " . $TableName . " ]<br /> " ; 121 // 表的字段个数 122 $FiledCount = mysql_num_fields ( $result ); 123 // 记录条数 124 $RecordCount = mysql_num_rows ( $result ); 125 126 echo " sql[ " . $sql . " ] 记录条数: " . $RecordCount . " <br /> " ; 127 128 if ( $FiledCount > 0 ) 129 { 130 echo " <table border='1'>; 131 <tr> 132 <th>记录序号</th> " ; 133 for ( $index = 0 ; $index < $FiledCount ; $index ++ ) 134 { 135 // 字段名 136 $FiledName = mysql_fetch_field ( $result ); 137 echo " <th> $FiledName ->name</th> " ; 138 } 139 echo " </tr> " ; 140 $No = 0 ; 141 while ( $row = mysql_fetch_array ( $result )) 142 { 143 $No = $No + 1 ; 144 echo " <tr> " ; 145 echo " <td> " . $No . " </td> " ; 146 for ( $index = 0 ; $index < $FiledCount ; $index ++ ) 147 { 148 echo " <td> " . $row [ $index ] . " </td> " ; 149 } 150 echo " </tr> " ; 151 } 152 echo " </table> " ; 153 154 } 155 } 156 157 158 159 160 mysql_close ( $con ); 161 ?> 162 163 <? php 164 // xml解析 165 echo " <br /> " . " ********xml解析******** " . " <br /> " ; 166 167 /* $xmlDoc = new DOMDocument(); 168 $xmlDoc->load("note.xml"); 169 170 $x = $xmlDoc->documentElement; 171 foreach ($x->childNodes AS $item) 172 { 173 print $item->nodeName . " = " . $item->nodeValue . "<br />"; 174 } */ 175 $xml = simplexml_load_file ( " note.xml " ); 176 177 echo $xml -> getName() . " <br /> " ; 178 179 foreach ( $xml -> children() as $child ) 180 { 181 echo $child -> getName() . " : " . $child . " <br /> " ; 182 } 183 ?> 184 185 <? php 186 // ajax 187 echo " <br /> " . " *******ajax******* " . " <br /> " ; 188 ?> 189 < form > 190 First Name : 191 < input type = " text " id = " txt1 " 192 // onkeyup="showHint(this.value)" 193 onkeyup = " Show() " > 194 </ form > 195 196 < p > Suggestions : < span id = " txtHint " ></ span ></ p > 197 198 199 </ body > 200 201 </ html > </p>
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

Simplified HTTP Response Mocking in Laravel Tests

Build a React App With a Laravel Back End: Part 2, React

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon
