Blogger Information
Blog 26
fans 0
comment 0
visits 15655
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
php数据类型与检测
庄周梦蝶
Original
577 people have browsed it

PHP程序运行原理

浏览器接受到网站文件->传给Apache服务器,Apache服务器查看是什么文件,是HTML就解析返回给浏览器,是PHP就传给PHP模块->PHP解析完后穿给Apache服务器,Apache服务器再传到浏览器

php与html混编的方式与短标签的使用

只有文件里面有PHP代码,文件的后缀名就必须是PHP

  1. <html>
  2. <head>
  3. <?php
  4. echo '<h2 style="color:red">您好,老师</h2>';
  5. ?>
  6. <? echo '<h2>您好,老师</h2>'?>
  7. <?= '<h2>您好,老师</h2>'?>
  8. <?php $st='<h2>您好,老师</h2>'?>
  9. <?=$st?>
  10. </head>
  11. <body>
  12. </body>
  13. </html>

常用数据类型

  1. 基本类型
    1-1.布尔类型
  1. <html>
  2. <heab>
  3. <?php
  4. $passed=true;
  5. echo $passed,'<hr>';
  6. echo gettype($passed),'<hr>';
  7. var_export($passed);
  8. echo '<hr>';
  9. var_dump($passed);
  10. ?>
  11. </heab>
  12. <body>
  13. </body>
  14. </html>


1-2.数值类型:整数,小数

  1. <html>
  2. <heab>
  3. <?php
  4. $srt=4899;
  5. $srr=4.48;
  6. var_dump($srt,$srr);
  7. ?>
  8. </heab>
  9. <body>
  10. </body>
  11. </html>


1-3.字符串

  1. <html>
  2. <heab>
  3. <?php
  4. $name='admin';
  5. $email='admin@qq.com';
  6. echo 'name:',$name,'<br>email:',$email;
  7. echo'<hr>';
  8. echo'hello "今天"<br>';
  9. echo'heool \'明天\'<br>';
  10. echo'c:\www\\tavv\i.html';
  11. ?>
  12. </heab>
  13. <body>
  14. </body>
  15. </html>


2.复合类型
2-1.数组

  1. <html>
  2. <heab>
  3. <?php
  4. $srt=[1,'牛牛','js',80];
  5. echo 'id=',$srt[0],'<br>';
  6. echo 'name:',$srt[1],'<br>';
  7. echo'kemu',$srt[2],'<br>';
  8. echo'cj',$srt[3],'<br>';
  9. //动态添加
  10. $srt[4]=true;
  11. echo'passd',$srt[4],'<br>';
  12. //追加添加
  13. $srt[]=24;
  14. echo'sj',$srt[5],'<br>';
  15. //使用追加创建数组
  16. $sss=[];
  17. $sss[]='蓝蓝的天空';
  18. $sss[]='飞老鹰';
  19. echo $sss[0],$sss[1],'<br>';
  20. $ser=['id'=>1,'name'=>'牛牛','kemu'=>'js','cj'=>80];
  21. echo 'id=',$ser['id'],'<br>';
  22. echo 'name=',$ser['name'],'<br>';
  23. echo 'kemu=',$ser['kemu'],'<br>';
  24. echo 'cj=',$ser['cj'],'<br>';
  25. //通过print_r(),显示关联数组
  26. print_r($ser);
  27. echo '<br>';
  28. echo print_r($ser,true);
  29. echo '<hr>';
  30. echo '<pre>'.print_r($ser,true).'</pre>';
  31. ?>
  32. </heab>
  33. <body>
  34. </body>
  35. </html>


2.2对象

  1. <html>
  2. <heab>
  3. <?php
  4. $a=1;
  5. $b=2;
  6. function sum($a,$b){
  7. return $a.'+'.$b.'='.($a+$b);
  8. }
  9. echo sum($a,$b),'<br>';
  10. //对象模版/类
  11. class Demo{
  12. private $a=1;
  13. private $b=2;
  14. public function sum(){
  15. return $this->a.'+'.$this->b.'='.($this->a+$this->b);
  16. }
  17. }
  18. $obj=new Demo();
  19. echo $obj->sum(),'<br>';
  20. ?>
  21. </heab>
  22. <body></body>
  23. </html>

Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post