PHP学习

1.PHP数组的创建用array()函数,PHP数组元素的动态添加用array_push()函数。

<?php
$a=array("Dog","Cat");
array_push($a,"Horse","Bird");
print_r($a);
?>

2.PHP字符串替换:

str_replace(find,replace,string,count)
参数 描述
find 必需。规定要查找的值。
replace 必需。规定替换 find 中的值的值。
string 必需。规定被搜索的字符串。
count 可选。一个变量,对替换数进行计数。

程序例子

view plain copy to clipboard print ?
  1. <?php  
  2.     echo str_replace("world","Gonn","Hello world!");  
  3. ?>    

运行结果:

Hello Gonn!    

就是说,用 Gonn 来替换掉 "Hello world!" 中的 world。

程序例子

在本例中,我们将演示带有数组和 count 变量的 str_replace() 函数:

view plain copy to clipboard print ?
  1. <?php  
  2.     $arr = array("blue","red","green","yellow");  
  3.     print_r(str_replace("red","pink",$arr,$i));  
  4.     echo "Replacements: $i";  
  5. ?>    

运行结果:

Array
(
    [0] => blue
    [1] => pink
    [2] => green
    [3] => yellow
)
Replacements: 1    

就是说,用 pink 替换掉数组中的 red。然后计算替换的次数。

程序例子

view plain copy to clipboard print ?
  1. <?php  
  2.     $find = array("Hello","world");  
  3.     $replace = array("B");  
  4.     $arr = array("Hello","world","!");  
  5.     print_r(str_replace($find,$replace,$arr));  
  6. ?>    

运行结果:

Array
(
    [0] => B
    [1] => 
    [2] => !
)

3.Ajax数据库

function getCommentDetail (id)
{
	alert(id);
	$.ajax({
		type:"POST",
		url:"http://localhost/EShop/items/js/index/ajax_part.php",
		data:{product_id :id}//这两个变量不能重名
		/*success:function(strValue)
		{
			alert(strValue);
		}*/
	});
}
其中poroduct和id代表的变量不能重名,否则会有意想不到的错误。

更新中。。。。。

你可能感兴趣的:(PHP,数据库,String,function,url)