IQ绿色电脑总站 IQ绿色下载站 IQ电脑图片 IQ丁香鱼电脑站
网站首页 | 网络编程 | 站长学院 | 网页制作 | 图形图像 | 操作系统 | 冲浪宝典 | 软件教程 | 网络办公 | 邮件系统 | 网络安全 | 电脑故障 | 访客留言 | 内容搜索
>首页 -> 网络编程 -> PHP编程 -> php实例

TOP

搜索外部或内部的网页
[ ]
 昨天我小姐? lol :)  I got a few emails saying, "I can't see the diary entry."  The reason you couldn't see one is because there wasn't one :) I am going to try and study PHP every day until I feel that I no longer need to study aloud and online. 上海: )我获得了一些电子邮件说: “我无法看到的日记。 ”原因你不能看到一个是因为没有一个: )我要努力学习PHP的每一天,直到我觉得我不再需要研究和在线出声。 I work some days in excess of 15 hours and have no time to study, so if you see no diary entry, I either didn't learn anything new or I didn't study that particular day. 我工作的一些天超过15小时,没有时间来研究,因此,如果您没有看到日记,我可能没有学到什么新的或我没有研究,特别的日子。 Whenever I write something, I do it in a sense *live* therefore you shortly after I code the HTML and hit save, my FTP editor FTPs these changes immediately onto the website. 每当我写的东西,我这样做在一定意义上*生活*因此,您不久之后,我的代码的HTML和储存触及,我的FTP编辑FTPs这些变化立即进入网站。 I suppose I could just add an entry to say hello or something, or ramble aloud about what I ate for the day, but I think you would grade me down on the useful rating scale considerably if I did do that. 我想我可以添加一个条目,以打招呼或东西,或漫步大声什么我吃的一天,但我认为你会年级对我有用的等级大大如果我没有做到这一点。 Who knows, though? 谁知道呢? I may do that once in awhile.  Anyway, the readership of these diary entries is increasing, according to my access logs, and I thank you for tuning in, so to speak. 我可以这样做,一旦在一段时间。总之,读者对这些日记是越来越多,据我访问日志,并感谢你给我调整,所以发言。 How long these diary entries continue will be in direct proportion to the learning I do, and the number of email requests I get to explore PHP further. 多久这些日记将继续成正比的学习我和一些电子邮件要求我要进一步探索PHP的。 Please take a minute and use the form to send me ideas for future diary entries, if you would like to see me explore a new topic, or an existing one in greater depth. 请花一分钟使用的形式寄给我的想法为今后的日记,如果你想看看我探索的新课题,或现有一个更加深入。 I have learned a great deal already and have started several new PHP scripts projects that will show up as full script downloads in the future. 我学到了很多已经并已开始一些新的PHP脚本项目,这些项目将显示为全面脚本下载的未来。 With the information in these diary entries, you should have been able to start some PHP projects of your own, as well :) 随着信息在这些日记,你应该已经能够启动一些项目的PHP自己,以及: )

Searching website URLS 搜索网站网址

This diary is starting to grow with information and some type of search engine would be useful to allow people to get directly and quickly to the information they are interested in. In some ways a linear approach would be best (starting along with me at the beginning of the diary and moving through in chronological order, since this is an evolving website based on my learning in stages) and also since I have split my learning over several days. 这日记开始增长,信息和某些类型的搜索引擎将是有益的,使人们获得直接和迅速的信息,他们感兴趣的在某些方面,线性的办法是最好的(开始与我一起开始在这本日记移动通过按时间顺序排列,因为这是一个不断发展的基础上的网站我学习的阶段) ,还因为我已经分手了我学习的好几天。 I wish I had more time to make a full lesson per day to keep this more cohesive, but such is the life of a true and yet (relatively) unedited diary. 我希望我有更多的时间充分的教训每天保持这一更具凝聚力的,但这样的生活是一个真正的和尚未(相对)未经编辑的日记。 At any rate, if I wanted to find out about searching using PHP and wanted to get to it fast, a search engine in some capacity would be a nice feature for you (and me, in the future actually, when I need to reference back to something). 无论如何,如果我想了解搜索使用PHP ,并希望得到它速度快,搜索引擎在某些能力将是一个很好的功能你(和我,在未来的实际,当我需要参考回来的东西) 。 Well that's what I'm working on next. 那么这就是我对明年的工作。 PHP offers a pretty convenient way to search an entire page. PHP提供一个相当便捷的方式来搜寻了一个整版。 How good is your memory? 如何很好的是你的记忆? Let's write a quick script to search New Year's Day's diary entry for keywords. First, of course we need a search box: 让我们写脚本的快速搜索元旦的日记中的关键字。首先,我们当然需要有一个搜索框:

Example #20 : Simple search for keyword at a URL 例如# 20 :简单的搜索关键字的网址

< form method=" POST " action=" example20.php3 " > 形式 方法= ” 报“ 的行动= ” example20.php3
< p >< input type=" text " name=" search_criteria " size=" 20 " > p ” “ 输入类型 = 文本“ 名称= ” search_criteria “大小= ” 20 “
< input type=" submit " value=" Search! " >< /p > 输入类型 = 提交“值= 搜索 ” “ /人
< /form > /表格

Nothing fancy needed for this beginning example. 没有想象这需要一开始的例子。 I have linked the box above to the script code I'm about to show you. 我已经联系上面的框中的脚本代码我要告诉你。 Go ahead (no looking back and cheating now) and type a word or two you think was probably contained in that HTML page. 往前冲(没有回头看现在和作弊) ,并输入一个字或两个你认为可能是载于该网页。 All the script does is tell you whether or not it is there and how many times the search criteria appeared on each line of HTML. Here's the code to do this: 所有的脚本是告诉你它到底是不是有多少次的搜索标准出现在每一行的HTML 。代码做到这一点:



“ ?
$size = 0; $大小= 0 ;
$url = "http://www.php-scripts.com/php_diary/010100.php3"; $网址= “ http://www.php-scripts.com/php_diary/010100.php3 ” ;
$the_page = fopen ($url, "r"); $ the_page = 打开 ( $网址, “ r ”开始) ;
while(!feof($the_page)) 而( ! feof ( $ the_page ) )
{
$each_line = fgetss ($the_page, 255); $ each_line = fgetss ( $ the_page , 255 ) ;
if( eregi ($search_criteria, $each_line, $results)) 如果( eregi ( $ search_criteria , $ each_line , $结果) )
{
// for each line where there is a match, increment a counter / /每行,其中有一个比赛,反增
$size++; $大小+ + ;
}
}
fclose ($the_page); fclose ( $ the_page ) ;
print("I found $size ocurrences of $search_criteria at $url"); 打印( “我发现大小ocurrences $美元search_criteria为网址” ) ;
?> ? “
“ /体重”
“ /的HTML ”

The script above, although rudimentary, illustrates scanning an internal or external website URL. 以上脚本,虽然简陋,说明扫描内部或外部网站网址。 Another and maybe faster (I haven't done a benchmark test, so I am not sure) way of doing an internal (or local) search would be to simply open the file using the file command, fill an array and then check each item in the array. 另一种可能更快(我没有做了基准测试,所以我不知道)的方式做一个内部(或地方)的搜索将是简单地打开该文件使用的文件的命令,填补了一系列然后检查每个项目在阵列。 You just replace $url with the actual URL you want to search. 你刚才取代$网址与实际网址您要搜寻。 Of special note is the function fgetss which is slightly different than fgets . 特别值得注意的是,功能fgetss这是比略有不同fgets With fgetss PHP attempts to remove any HTML or PHP code before matching. 随着PHP的fgetss试图删除任何HTML或PHP代码前匹配。 Again you could substitute eregi with ereg and thus have a case sensitive search. 再次你可以代替eregi额日格 ,从而有区分大小写的搜索。 Therefore, it would be quite easy to create a branch of code that checked whether the search should be for exact matches or "similar" matches, the case being the identifier. 因此,将很容易创建的一个分支代码,检查是否搜索应该是完全匹配或“类似”几场比赛中,案件的标识。 Add a dropdown menu to your search form box with the name of "type" and then pass the value of "exact" for case sensitive matches. 添加一个下拉菜单搜索框形式的名称“输入” ,然后通过价值的“确切”的大小写匹配。 You would then modify the above code to read: 您然后将修改上述代码如下:

$each_line = fgetss ($the_page, 255); $ each_line = fgetss ( $ the_page , 255 ) ;
if($type != "exact" 如果( $型! = “确切”
{
if( eregi ($search_criteria, $each_line, $results)) 如果( eregi ( $ search_criteria , $ each_line , $结果) )
{
// for each line where there is a match, increment a counter / /每行,其中有一个比赛,反增
$size++; $大小+ + ;
}
}
else 其他的
{
// ok let search using CASE SENSITIVE matches only / /玉让搜索使用区分大小写场比赛只
if( ereg ($search_criteria, $each_line, $results)) 如果( 额日格 ( $ search_criteria , $ each_line , $结果) )
{
// for each line where there is a match, increment a counter / /每行,其中有一个比赛,反增
$size++; $大小+ + ;
}
}

Please vote on what you think of this diary entry :) 请投票你觉得这个日记: )

[上一篇]PHP中类的静态成员 [下一篇]PHP AJAX example: asynchronous ..

评论

称  呼:
内  容:

精彩文章地带

相关栏目

最新文章

热门文章

推荐文章