標籤:
<?php$a1="hello";$a2="hell";echo strlen($a1);echo strcmp($a1,$a2)."<br/>";//拆分字串$str="hello|nihao|worde|name";$arr1=explode("|",$str);echo $arr1[2]."<br/>";//數組轉化為字串$arr2=array("11","22","33","44","55");echo implode($arr2)." ";//替換字串,從某個位置開始替換$th=substr_replace($a1,"bb",0,2);echo $th."<br/>";//替換字串,原有字元替換成新的$s = "hello";$a = str_replace("l","a",$s);echo $a."<br/>";//截取字串$jq=substr($s,0,3);echo $jq;//字元在字串中的位置$s1="nihao";echo strpos($s1,h); $host="localhost"; $uid="root"; $pwd="root"; $database="info"; $conn=mysql_connect($host,$uid,$pwd); if($conn==false){echo "串連失敗";}else{echo "串連成功";} mysql_select_db($database,$conn); mysql_query("create database xuexi,$conn"); $result= mysql_query("select * from DL"); $ss=""; while( $row=mysql_fetch_row($result)) { $ss=$ss.$row[2]." "; } echo $ss; //1產生連線物件 $db = new mysqli($host,$uid,$pwd,$database);//2.判斷是否串連成功if(mysqli_connect_error()){echo "串連失敗!";exit; //退出}//執行MYSQL語句$result=$db->query("select * from DL");$zz="<select>";//遍曆數組中資料,做下拉式功能表while($row = $result->fetch_row()/*擷取傳回值,返回是數組*/){$zz = $zz."<option value=‘".$row[1]."‘>".$row[2]."</option>";} $zz."</select>";echo $zz;
php 字串及串連資料庫基本知識點