php题目

创建多级目录函数   mkdir();

获取网页内容函数 fiel_get_content();   输出  file_put_content();

parse_url()  解析一个url  以数组的形式输出 host path query(参数)
pathinfo   解析path(路径)  以数组的形式输出 文件 文件名 后缀 

相对路径计算

function getRelativePath($path1, $path2)
{
    $arr1 = explode('/', $path1);
    $arr2 = explode('/', $path2);
    // 获取相同路径的部分
    $intersection = array_intersect_assoc($arr1, $arr2);
    $same = 0;                          // 相同目录的个数
    for($i=0,$len=count($intersection); $i<$len; $i++)      // 过滤不存在的值,防止下标0相等 3相等情况
    {
        $same = $i;
        if(!isset($intersection[$i]))   // 没有设置这个值
        {
            break;
        }
    }
    // 前面全部匹配
    if($i==count($intersection))
    {
        $same ++;
    }

    // 将path2的/ 转为 ../,path1获取后面的部分,然后合拼
    // 计算前缀
    if(count($arr2)-$same-1>0)
    {
        $prefix = array_fill(0, count($arr2)-$same-1, '..');
    }
    else
    {
        $prefix = array('.');
    }

    $tmp = array_merge($prefix, array_slice($arr1, $same));
    $relativePath = implode('/', $tmp);
    return $relativePath;
}

$path1 = '/home/web/lib/img/cache.php';
$path2 = '/home/show.php';
echo getRelativePath($path1, $path2).'<br>';

获取数组键值

print_r(array_keys($arr));
print_r(array_values($arr));

连接数据库

$con=mysqli_connect("localhost","root","","xinwen");
if (!$con)
{
    die("Connection failed: " . mysqli_connect_error());
}
$sql = "select * from news ";
$result =$con->query($sql);
if($result==true)
{
    while ($attr = $result->fetch_row())
    {
        echo "<tr>
                <td>{$attr[0]}</td>
             </tr>";
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值