Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2860775
  • 博文数量: 178
  • 博客积分: 2076
  • 博客等级: 大尉
  • 技术积分: 2800
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-10 10:50
文章分类

全部博文(178)

文章存档

2010年(4)

2009年(13)

2008年(161)

我的朋友

分类: LINUX

2008-11-04 00:39:58

  //变量的变量--动态
  $my="xiaone";
  $$my="MARRY";
  echo "$my";
  echo $$my;
  $my="test";
  echo $$my;// null;
  define("TEST","THIS IS THE FIRST VARIOUS\n");
  echo  TEST;
  if(defined("TEST")){
      echo "test have been defined \n";
 
  }
 
  // PHP的运算符
  //位运算符
  $a=5;
  $b=7;
  $var=$a|$b;
  echo $var;
  echo "$a\+$b";
  echo "---------------------------------\n";
  echo "10大于是100?".(10>100?"TRUE":"FALSE")."
";
 
  $a=20;
  echo "++a:".++$a."
";
  echo "a :".$a."
";
  $a=20;
  echo "a++".$a++."
";
  echo "a : ".$a."
";
 
  //switch
  $i=1;  //empty(var)如果var是非空或非0的值则返回false
  if (!empty($i)){
     switch($i){
    
     case 0:
       print "i is 0";break;
     case 1:
       print "i is not 0";break;
      
     }
 
 
  }
  else print 'empty i\n';
       //数组的应用.
       $array=array(1,2,3,4,5);
       echo "
";
       print_r($array);
       echo "
";
       foreach ($array as $i1=>$va){
       print $array[$i1]."
";
       }
       $bar1=each($array);
      /* foreach ($bar1 as $k=>$v)
       {
        echo "$k:$v
";
       }*/
      echo "abv===================================,
";
      reset($array); // $array point to zero;
       while(list($k,$v)=each($array)){
           print "$k:$v
";
      
       }
       reset($array);
       $one=array_shift($array);
       print $one."
";//返回第一个元素;一定要用变量储存
       reset($array);
     echo "此时我再打印出数组
";  //array_unshift (&array,mixed var);            
        while(list($k,$v)=each($array)){
           print "$k:$v
";
      
       }
       reset($array);
       //arrary_pop (&array) end9&array)将指针指向最后一个元素
       //current(&array)返回当前元素的值
       //
       //引用传递参数
       $num=100; //下面试图改变其值
       echo "原来的\$num 是 $num
";
       function addchange($nu){
        $nu+=1;
        Echo $nu;
       }
       addchange(&$num); //这里利用了引用的定义,对引用变量的改变值同时也作用
       //于原来的变量.
       echo "调用了addchange(&\$num)后的 \$num为
";
       echo "$num
";
       echo "function 的默认值勤
";
       function hoo($str="sports"){
      
        return "my love is $str
";
       }
       echo hoo();
       echo hoo("eating");
       //从内部函数访问外部变量
       $test1=1;
       $test2=2;
       function sum(){
         global $test1,$test2;
         return $test1+$test2;
       }
       echo sum()."
";
       function test(){
        static $a11=0;
        echo "$a11
";
        $a11++;
       }
       test();   test();     test();    
       echo $a11;
      
       //date
       $to_date=date("l m.d.y");
       print "$to_date
";
       $today=getdate();
       print_r($today);
      
      
      
      
       //traint                      //PHP返回要对应,不然会打砸抢
       $lower=" I WANT TO MAKE MONEY";
       $lower1=strtolower($lower);
       echo "
strtolower for string :$lower1
";
       $upper=" i want to talk to y";
       $upper1=strtoupper($upper);
       echo  "
strtoupper for string :$upper1
";
       echo "
将字符串的首个字符转化成大定ucfirst
";
       $uc="if love you ";
       $uc1=ucfirst($uc);
       echo "ucfirst : $uc1
";
       echo "将字符串的单词的首个字符转化成大写ucwords
";
       $ucwd=ucwords($uc);
       echo "ucwords :$ucwd
";
       echo "=====================================
";
       //htmlspecialchars()奖一些HTML标记转换成文本实体
       $new=htmlspecialchars("test",ENT_QUOTES);
       echo "$new
";
       $newentites=htmlentities("t",ENT_QUOTES);
       echo "htmlentities :$newentites
";
       echo "=====================================
";
       echo "字符串查找:
";
       $email="";
       $domail=strstr($email,'@');
       echo "the find function :$domail
";
       echo "=====================================
";
        echo "不区分大写查找
";
        $email1="";
        $domail=stristr($email1,'@');
        echo "stristr find :$domail
";
       echo "=====================================
";
       echo "查找最后一个字符串strchr
";
          echo "path:$PATH
";
          $dir=strchr($PATH,":");
          echo "the last path : $dir
";
       echo "=====================================
";
          echo "定位字符串
";
               $stringmy="abc";
               $pos=strpos($stringmy,'a',0);  //找不到会返回false
               if($pos===false){
               echo "i cant find the words a
";
              
               }else{
                  echo "I can find the words 'a' and its position is $pos
";
               }//strrpos 同strpos一样,只是它返回的是最后一次出现的的子字符的位置.
               //stripos-strpos strripos--strrpos
       echo "=====================================
";
               echo "str_replace(search,replace,orgstr,[times]) 字串替换
";
                                   $bodytag=str_replace("%body%","black","");
                                   $a=htmlspecialchars("");
                                   $a_change=htmlspecialchars($bodytag);
                                   echo "原字符串:$a
";
                                   echo "str_replace(search,replace,orgstr,[times])后$a_change
";
               echo "将数组设定的元素替换成值
";
               $volwes=array("h","a","t");
               $re_str=str_replace($volwes,"","hello the world!");
               echo "将数组设定的元素替换成空值,其实就是把seach 指定为array:
";
               echo "替换后的字符串:$re_str
";
               echo "在字符串中查找一个数组中设定的内容
";
               $pase="you should go to eat fruits,vegetables,nad fiber";
               echo $pase."
";
               $healthy=array("fruits","vegetables","fiber");
               $y_change=array('orange','apple','icecream');
               $newreplace=str_replace($healthy,$y_change,$pase);   //str_ireplace(search,replace,org,[times]);
                 echo " 在字符串中查找一个数组中设定的内容
";
                  echo "$newreplace
";
                                   //sub_replace(org,replace,start,length);
          echo "=====================================
";
          if(preg_match()
             echo "=====================================
";
                echo "=====================================
";
?>
 
 
xiaoneMARRYTHIS IS THE FIRST VARIOUS test have been defined 75\+7--------------------------------- 10大于是100?FALSE
++a:21
a :21
a++20
a : 21
i is not 0
Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => 5 )
1
2
3
4
5
abv===================================,
0:1
1:2
2:3
3:4
4:5
1
此时我再打印出数组
0:2
1:3
2:4
3:5
原来的$num 是 100
101调用了addchange(&$num)后的 $num为
101
function 的默认值勤
my love is sports
my love is eating
3
0
1
2
Monday 11.03.08
Array ( [seconds] => 28 [minutes] => 51 [hours] => 15 [mday] => 3 [wday] => 1 [mon] => 11 [year] => 2008 [yday] => 307 [weekday] => Monday [month] => November [0] => 1225727488 )
strtolower for string : i want to make money

strtoupper for string : I WANT TO TALK TO Y

将字符串的首个字符转化成大定ucfirst
ucfirst : If love you
将字符串的单词的首个字符转化成大写ucwords
ucwords :If Love You
=====================================
test
htmlentities :t
=====================================
字符串查找:
the find function :@163.com
=====================================
不区分大写查找
stristr find :@MYLOVE.COM
=====================================
查找最后一个字符串strchr
path:
the last path :
=====================================
定位字符串
I can find the words 'a' and its position is 0
=====================================
str_replace(search,replace,orgstr,[times]) 字串替换
原字符串:
str_replace(search,replace,orgstr,[times])后
将数组设定的元素替换成值
将数组设定的元素替换成空值,其实就是把seach 指定为array:
替换后的字符串:ello e world!
在字符串中查找一个数组中设定的内容
you should go to eat fruits,vegetables,nad fiber
在字符串中查找一个数组中设定的内容
you should go to eat orange,apple,nad icecream
=====================================
=====================================
=====================================
阅读(621) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~