PHP 高级工程面试题汇总
1、给你四个坐标点,判断它们能不能组成一个矩形,如判断([0,0],[0,1],[1,1],[1,0])能组成一个矩形。
勾股定理,矩形是对角线相等的四边形。只要任意三点不在一条直线上,任选一点,求这一点到另外三点的长度的平方,两个短的之和如果等于最长的,那么这就是矩形。
2、写一段代码判断单向链表中有没有形成环,如果形成环,请找出环的入口处,即P点
/*
*单链表的结点类
*/
class LNode{
//为了简化访问单链表,结点中的数据项的访问权限都设为public
public int data;
public LNode next;
}
class LinkListUtli {
//当单链表中没有环时返回null,有环时返回环的入口结点
public static LNode searchEntranceNode(LNode L)
{
LNode slow=L;//p表示从头结点开始每次往后走一步的指针
LNode fast=L;//q表示从头结点开始每次往后走两步的指针
while(fast !=null && fast.next !=null)
{
if(slow==fast) break;//p与q相等,单链表有环
slow=slow.next;
fast=fast.next.next;
}
if(fast==null || fast.next==null) return null;
// 重新遍历,寻找环的入口点
slow=L;
while(slow!=fast)
{
slow=slow.next;
fast=fast.next;
}
return slow;
}
}
3、写一个函数,获取一篇文章内容中的全部图片,并下载
function download_images($article_url = '', $image_path = 'tmp'){
// 获取文章类容
$content = file_get_contents($article_url);
// 利用正则表达式得到图片链接
$reg_tag = '/<img.*?\"([^\"]*(jpg|bmp|jpeg|gif|png)).*?>/';
$ret = preg_match_all($reg_tag, $content, $match_result);
$pic_url_array = array_unique($match_result1[1]);
// 创建路径
$dir = getcwd() . DIRECTORY_SEPARATOR .$image_path;
mkdir(iconv("UTF-8", "GBK", $dir), 0777, true);
foreach($pic_url_array as $pic_url){
// 获取文件信息
$ch = curl_init($pic_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$fileInfo = curl_exec($ch);
$httpinfo = curl_getinfo($ch);
curl_close($ch);
// 获取图片文件后缀
$ext = strrchr($pic_url, '.');
$filename = $dir . '/' . uniqid() . $ext;
// 保存图片信息到文件
$local_file = fopen($filename, 'w');
if(false !== $local_file){
if( false
