The content introduced in this article is a summary of PHP interview questions, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it
Related recommendations: "2019 Summary of PHP interview questions (collection) 》
1. What is object-oriented? What are the main features?
Object-oriented is a design method for programs, which helps improve the reusability of programs and makes the program structure clearer. Main features: encapsulation, inheritance, polymorphism.
2. What is the difference between SESSION and COOKIE? Please explain the reasons and functions from the protocol?
1. http is stateless The protocol cannot distinguish whether the user comes from the same website. The same user requesting different pages cannot be regarded as the same user.
2. SESSION is stored on the server side, and COOKIE is stored on the client side. Session is relatively secure. Cookies can be modified by certain means and are not safe. Session relies on cookies for delivery.
After disabling cookies, the session cannot be used normally. Disadvantages of Session: It is saved on the server side. Every time it is read, it is read from the server, which consumes resources on the server. Session is saved in a file or database on the server side. It is saved in a file by default. The file path is specified by session.save_path in the PHP configuration file. Session files are public.
3. What do the 302, 403, and 500 codes in the HTTP status mean?
One, two, three, four and five principles: 1. Message series 2. Success series 3. Redirect series 4. Request error series 5. Server-side error series
302: Temporary transfer successful , the requested content has been moved to a new location 403: Access Forbidden 500: Server Internal Error 401 represents unauthorized.
4. The command to create a compressed package and decompress the package under Linux
Tar.gz:
Packaging:tar czf file.tar.gz file.txt
Decompression: tar xzf file.tar.gz
Bz2:
Packaging: bzip2 [-k] File
Decompression: bunzip2 [-k] file
Gzip (only for files, the original file is not retained)
Packaging: gzip file1.txt
Decompression: gunzip file1. txt.gz
Zip: -r Pack directory
: zip file1.zip file1.txt
Decompress: unzip file1.zip
5. Please write down the meaning of data type (int char varchar datetime text); what is the difference between varchar and char?
Int Integer char fixed-length character Varchar variable-length character Datetime date and time type Text text type The difference between Varchar and char char is a fixed-length character type. How much space is allocated, How much space does it take up. Varchar is a variable-length character type. It takes up as much space as the content is, which can effectively save space. Since the varchar type is variable, the server has to perform additional operations when the data length changes, so the efficiency is lower than that of the char type.
6. What are the basic differences between MyISAM and InnoDB? How is the index structure implemented?
The MyISAM type does not support transactions and table locks, and is prone to fragmentation. It needs to be optimized frequently and has faster reading and writing speeds, while the InnoDB type supports transactions, row locks, and has crash recovery capabilities. Read and write speeds are slower than MyISAM.
Create index: alerttable tablename add index (`field name`)
7. Send a cookie to the client without using cookies.
Understanding: When session_start() is turned on, a constant SID is generated. When COOKIE is turned on, this constant is empty. When COOKIE is turned off, the value of PHPSESSID is stored in this constant. By adding a SID parameter after the URL to pass the value of SESSIONID, the client page can use the value in SESSION. When the client opens COOKIE and the server opens SESSION. When the browser makes the first request, the server will send a COOKIE to the browser to store the SESSIONID. When the browser makes the second request, the existing
8. isset() and empty( ) Difference
Isset determines whether the variable exists. You can pass in multiple variables. If one of the variables does not exist, it returns false. empty determines whether the variable is empty and false. Only one variable can be passed. If Returns true if empty or false.
9. How to pass variables between pages (at least two ways)? GET, POST, COOKIE, SESSION, hidden form
1. Write a regular expression that matches the URL.
'/^(https?|ftps?):\/\/(www)\.( [^\.\/] )\.(com|cn|org)(\/[\w-\.\/\?\%\&\=]*)?/i'
2. Please write down a common sorting algorithm, and use PHP to implement bubble sorting, and sort the array $a = array() from small to large.
Common sorting algorithms: bubble sort, quick sort, simple selection sort, heap sort, direct insertion sort, Hill sort, merge sort.
The basic idea of the bubble sorting method is: perform multiple scans from back to front (reverse order) on the keywords of the records to be sorted. When it is found that the order of two adjacent keywords does not match the rules required for sorting, these will be Two records are exchanged. In this way, records with smaller keywords will gradually move from back to front, just like bubbles floating upward in water, so this algorithm is also called bubble sorting method.
// 冒泡排序法 Function mysort($arr){ For($i=0;$i<count($arr); $i++){ For($j=0; $j<count($arr)-1-$i; $j++){ If($arr[$j]> $arr[$j+1]){ $tmp=$arr[$j]; $arr[$j]=$arr[$j+1]; $arr[$j+1]=$tmp; } } } Return$arr; } $arr=array(3,2,1); print_r(mysort($arr));
3. Please explain the difference between passing by value and passing by reference in PHP. When to pass by value and when to pass by reference?
Pass by value: Any changes to the value within the function scope will be ignored outside the function
Pass by reference: Any changes to the value within the function scope will also be reflected outside the function Modify
Advantages and Disadvantages: When passing by value, PHP must copy the value. Especially for large strings and objects, this can be a costly operation. Passing by reference does not require copying the value, which is good for improving performance.
What is the function of error_reporting in PHP?
Set the error level of PHP and return to the current level.
Please use regular expression (Regular Expression) to write a function to verify whether the format of the email is correct.
if(isset($_POST['action']) && $_POST['action']==’submitted’){ $email=$_POST['email']; if(!preg_match(“/^[0-9a-zA-Z-]+@[0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+){1,3}$/”,$email)){ echo“电子邮件检测失败”; }else{ echo“电子邮件检测成功”; } }
Write a two-dimensional array sorting algorithm function that is versatile and can call the PHP built-in function (array_multisort())
//二维数组排序, $arr是数据,$keys是排序的健值,$order是排序规则,1是升序,0是降序 function array_sort($arr, $keys, $order=0) { if(!is_array($arr)) { return false; } $keysvalue =array(); foreach($arr as$key => $val) { $keysvalue[$key] = $val[$keys]; } if($order == 0){ asort($keysvalue); }else { arsort($keysvalue); } reset($keysvalue); foreach($keysvalueas $key => $vals) { $keysort[$key] = $key; } $new_array =array(); foreach($keysortas $key => $val) { $new_array[$key] = $arr[$val]; } return $new_array; }
Please use spaces as intervals to split the string 'Apple Orange BananaStrawberry' into an array $fruit,
* array All elements in are in lowercase letters and sorted in alphabetical order
class sort { private $str; public function__construct($str) { $this->str=strtolower($str); } private functionexplodes() { if(empty($this->str)) returnarray(); $arr=explode("",$this->str); return is_array($arr)?$arr:array($arr); } public functionsort() { $explode=$this->explodes(); sort($explode); return $explode; } } $str='Apple Orange Banana Strawberry'; $sortob=new sort($str); var_dump($sortob->sort());
For the user to input a string $string, it is required that $string can only contain For numbers and English commas greater than 0, please use regular expressions to verify. If $string does not meet the requirements, an error message will be returned
class regx { public staticfunction check($str) { if(preg_match("/^([1-9,])+$/",$str)){ return true; } return false; } } $str="12345,6"; if(regx::check($str)) { echo "suc"; } else { echo "fail"; }
Windows platform, Apache Http Server fails to start, what are the troubleshooting ideas?
Check whether port 80 used by apache is occupied. If it is occupied, stop occupying port 80 first. service, and then start the apache server
Where does the PHP session extension store session data by default? D
A) SQLite Database
B) MySQL Database
C) Shared Memory
D) File System
E) Session Server
If you want To automatically load a class, which of the following function declarations is correct? C
A) function autoload($class_name)
B) function __autoload($class_name, $file)
C) function __autoload($class_name)
D) function _autoload($class_name)
E) function autoload($class_name, $file)
PHP program uses utf-8 encoding, what is the output result of the following program? B
$str = 'hello hello world';
echo strlen ($str);
What php array-related functions do you know?
array()----Create an arrayarray_combine()----Create a new array by merging two arraysrange() ----Create and return an array containing elements in the specified range
compact()----Create an arrayarray_chunk()----Split an array into multiple array_merge()----Merge two or more arrays into one arrayarray_slice()----Remove a value from the array based on conditionsarray_diff()----Returns the difference array of two arraysarray_intersect()----Calculate the intersection of arraysarray_search()----In the array Search for a given valuearray_splice()----Remove part of the array and replace itarray_key_exists()----Determine whether the specified key exists in an arrayshuffle()----Rearrange the elements in the array in random orderarray_flip()----Exchange the keys and values in the arrayarray_reverse( )----Reverse the order of elements in the original array, create a new array and return array_unique()----Remove duplicate values in the arraySeveral methods and functions for reading file contents in php?
Open the file and read it. Fopen()fread()Open and read once and complete file_get_contents()
In the following program, what is the value of the variable str and enter 111?
if( ! $str ) { echo 111; }
The value in $str is: 0, '0′, false, null,""
What are some PHP technologies you know (smarty, etc.)?
Smarty,jquery,ajax,memcache,p css,js,mysqli,pdo,svn,thinkphp,brophp,yiiWhat you have What are the familiar PHP forum systems?
Discuz
你所熟悉的PHP商城系统 有哪些?
Ecshop
你所熟悉的PHP开发框架 有哪些?
Brophp,thinkphp
说说你对缓存技术的了解?
1、缓存技术是将动态内容缓存到文件中,在一定时间内访问动态页面直接调用缓存文件,而不必重新访问数据库。
2、使用memcache可以做缓存。
你所知道的设计模式有哪些?
工厂模式、策略模式、单元素模式、观察者模式、命令链模式
说说你对代码管理的了解?常使用那些代码版本控制软件?
通常一个项目是由一个团队去开发,每个人将自己写好的代码提交到版本服务器,由项目负责人按照版本进行管理,方便版本的控制,提高开发效率,保证需要时可以回到旧版本。
常用的版本控制器:SVN
说说你对SVN的了解?优缺点?
SVN是一种版本控制器,程序员开发的代码递交到版本服务器进行集中管理。
SVN的优点:代码进行集中管理,版本控制容易,操作比较简单,权限控制方便。
缺点:不能随意修改服务器项目文件夹。
怎么找到PHP.ini的路径?
一般都在php的安装目录下,或者window系统的windows目录下。
PHP加速模式/扩展? PHP调试模式/工具?
Zend Optimizer加速扩展
调试工具:xdebug
你常用到的mysql命令?
Show databases
Show tables
Insert into 表名()values()
Update 表名 set字段=值 where ...
Delete from 表名where ...
Select * from 表名where 条件 order by ... Desc/asc limit ... Group by ... Having ...
进入mysql管理命令行的命令?
Mysql -uroot -p回车密码
show databases; 这个命令的作用?
显示当前mysql服务器中有哪些数据库
show create database mysql; 这个命令的作用?
显示创建数据库的sql语句
show create table user; 这个命令的作用?
显示创建表的sql语句
desc user; 这个命令的作用?
查询user表的结构
explain select * from user; 这个命令的作用?
获取select相关信息
show processlist; 这个命令的作用?
显示哪些线程正在运行
SHOW VARIABLES; 这个命令的作用?
显示系统变量和值
SHOW VARIABLES like ’%conn%’; 这个命令的作用?
显示系统变量名包含conn的值
LEFT JOIN 写一个SQL语句?
SELECTA.id,A.class FROM A LEFT JOIN B ON A.cid=B.id
in, not ni, exist, not exist的作用和区别?
in在什么中
Not in 不在什么中
Exists 存在
Not exists 不存在
怎么找到数据库的配置文件路径?
在数据库安装目录下,my.ini
简述Linux下安装PHP的过程?
安装软件之前先安装编译工具gcc、gcc-c++
拷贝源码包,解包解压缩
Cd /lamp/php进入php目录
./configure–prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc指定安装目录和配置文件目录
Make 编译
Make install安装
简述Linux下安装Mysql的过程?
Groupadd mysql 添加一个用户组mysql
Useradd -gmysql mysql 添加一个mysql用户指定分组为mysql
Cd /lamp/mysql 进入mysql目录
./configure–prefix=/usr/local/mysql/ –with-extra-charsets=all
Make
Make all
简述Linux下安装apache的过程?
Cd /lamp/httpd 进去apache软件目录
./configure–prefix=/usr/local/apache2/ –sysconfdir=/etc/httpd/ –with-included-apr
Make
Make all
HTML/CSS/p/Javascritp:
1. 设计一个页面(4个 p 第一个p 宽960px 居中;第2-4个p 3等分960px;)
<style> Body{Text-align:center; Margin:0; Padding:0; } #box{Width:960px; Margin:0 auto; } .small{Width:320px; Float:left; } </style> <pid=’box’> <pclass=’small’></p> <pclass=’small’></p> <pclass=’small’></p> </p>
用javascript取得一个input的值?取得一个input的属性?
document.getElementById(‘name’).value; document.getElementById(‘name’).type;
用Jquery取得一个input的值?取得一个input的属性?
$(“input[name='aa']“).val(); $(“input[name='aa']“).attr(‘type’);
请您写一段ajax提交的js代码,或者写出ajax提交的过程逻辑。
var xmlhttp; if(window.XMLHttpRquest){ xmlhttp=newXMLHttpRequest(); }elseif(window.ActiveXObject){ xmlhttp=newActiveXObject(‘Microsoft.XMLHTTP’); } xmlhttp.open(‘GET’,’1.php?aa=name’,true); xmlhttp.onreadystatechange=function(){ if(xmlhttp.readyState==4){ if(xmlhttp.status==200){ var text=xmlhttp.responseText; } } } xmlhttp.send(null);
简述Cookie的设置及获取过程
设置COOKIE的值:
Setcookie(名称,值,保存时间,有效域);
获取值:$_COOKIE['名称'];
面向对象中接口和抽象类的区别及应用场景?
1、有抽象方法的类叫做抽象类,抽象类中不一定只有抽象方法,抽象方法必须使用abstract关键字定义。
2、接口中全部是抽象方法,方法不用使用abstract定义。
3、当多个同类的类要设计一个上层,通常设计为抽象类,当多个异构的类要设计一个上层,通常设计为接口。
用面向对象来实现A对象继承B和C对象
Interface B{... } Interface C{... } Class Aimplements B,C{ ... }
相关推荐:
The above is the detailed content of Summary of php interview questions. For more information, please follow other related articles on the PHP Chinese website!