解析PHP对现有搜索引擎的调用

yipeiwu_com7年前PHP代码库
复制代码 代码如下:

<?php
    $key = $_GET['key'];                        //获得关键字
    $select = $_GET['select'];                  //获得搜索引擎的选择
    switch($select)                             //根据搜索引擎的不同跳转到不同的页面
    {
        case "google":                          //GOOGLE
            $url = "http://www.google.com/search?q=".$key;
            header("Location: $url");
            break;
        case "yahoo":                           //YAHOO
            $url = "http://search.yahoo.com/search?p=".$key;
            header("Location: $url");
            break;
        case "baidu":                           //百度
            $url = "http://www.baidu.com/s?wd=".$key;
            header("Location: $url");
            break;
        default:                                //如果搜索引擎不存在,结束程序
            break;
    }
?>

运行结果如图36-4所示。


图36-4  PHP综合搜索引擎

单击【Submit】按钮后,可以看到Yahoo网站被打开了,并搜索到了相关的搜索结果,如图36-5所示。


图36-5  Yahoo的搜索结果

相关文章

php 中phar包的使用教程详解

php 中phar包的使用教程详解

修改配置文件: vim /usr/local/php/etc/php.ini [Phar] phar.readonly = Off 压缩: a. 创建压缩脚本: vim c...

PHP多进程简单实例小结

本文实例讲述了PHP多进程。分享给大家供大家参考,具体如下: PHP创建多进程需要使用到pcntl模块 在编译时加上--enable-pcntl打开进程控制支持,不是Unix类系统不支持...

php使用正则表达式获取图片url的方法

本文实例讲述了php使用正则表达式获取图片url的方法。分享给大家供大家参考。 具体实现方法如下: 复制代码 代码如下: <?php header("Content-typ...

PHP中读取文件的几个方法总结(推荐)

1.fread string fread ( int $handle , int $length ) fread() 从 handle 指向的文件中读取最多 length 个字节。该函数...

php中switch语句用法详解

本文介绍php中的switch语句的用法,它跟其他语句中的switch用法差不多的,但注意有有一个break语句。 PHP中switch语句的标准语法: switch (expre...