在编写php程序的时候,往往会出现对其post get 等的编码,于是就有对空格的处理,程序如下:
<?php
$file=file("D:\wwwroot\www\htdocs\sinanet.txt");
//$file=file("D:\wwwroot\www\htdocs\sinatest.txt");
$count=0;
$line=0;
for($i=0;$i<=count($file);$i++)
{
$line=$line+1;
echo $line."\n";
$result = explode("sinanet",$file[$i]);
for($j=0;$j<count($result);$j++)
{
if($result[$j])
{
$url="http://you.video.sina.com.cn/pg/search/iaskSearch.class.php?key=\"".urlencode($result[$j])."\"";
$judge=file_get_contents($url);
$judge_handle = strstr($judge,"抱歉");//专辑推荐
if($judge_handle)
{ $count=$count+1;
$rest = substr($judge_handle, 0, 14);
echo $rest;
echo "关键词:".$result[$j]."\n";
}else{
echo $url;
echo "\n关键词:".$result[$j]."可能没有出现抱歉***!"."\n";
}
}else{
echo "有问题:".$result[$j]."\n";
}
}
echo "\n";
}
echo "总共找到抱歉条目:".$count."分析文件".$line."行!";
?>
以上语句如果不用urlencode()来进行编码,往往容易出现问题,example:
<?php
$key = "Chinese Democracy";
$key = urlencode($key);
$url = "http://you.video.sina.com.cn/pg/search/iaskSearch.class.php?key=".$key;
$judge= file_get_contents($url);
echo $judge;
return;
$judge_handle = strstr($judge,"抱歉");//专辑推荐
if($judge_handle)
{
$count=$count+1;
$rest = substr($judge_handle, 0, 14);
echo $rest;
echo "关键词:".$result[$j]."\n";
}else{
echo $url;
echo "<br>关键词:".$result[$j]."可能没有出现抱歉***!"."\n";
}
?>
不加上urlencode会出现如下问题:$url = "http://you.video.sina.com.cn/pg/search/iaskSearch.class.php?key=’Chinese‘ 而不是:"Chinese Democracy",为此最好每次涉及到url的时候加上urlencode.
<?php
$file=file("D:\wwwroot\www\htdocs\sinanet.txt");
//$file=file("D:\wwwroot\www\htdocs\sinatest.txt");
$count=0;
$line=0;
for($i=0;$i<=count($file);$i++)
{
$line=$line+1;
echo $line."\n";
$result = explode("sinanet",$file[$i]);
for($j=0;$j<count($result);$j++)
{
if($result[$j])
{
$url="http://you.video.sina.com.cn/pg/search/iaskSearch.class.php?key=\"".urlencode($result[$j])."\"";
$judge=file_get_contents($url);
$judge_handle = strstr($judge,"抱歉");//专辑推荐
if($judge_handle)
{ $count=$count+1;
$rest = substr($judge_handle, 0, 14);
echo $rest;
echo "关键词:".$result[$j]."\n";
}else{
echo $url;
echo "\n关键词:".$result[$j]."可能没有出现抱歉***!"."\n";
}
}else{
echo "有问题:".$result[$j]."\n";
}
}
echo "\n";
}
echo "总共找到抱歉条目:".$count."分析文件".$line."行!";
?>
以上语句如果不用urlencode()来进行编码,往往容易出现问题,example:
<?php
$key = "Chinese Democracy";
$key = urlencode($key);
$url = "http://you.video.sina.com.cn/pg/search/iaskSearch.class.php?key=".$key;
$judge= file_get_contents($url);
echo $judge;
return;
$judge_handle = strstr($judge,"抱歉");//专辑推荐
if($judge_handle)
{
$count=$count+1;
$rest = substr($judge_handle, 0, 14);
echo $rest;
echo "关键词:".$result[$j]."\n";
}else{
echo $url;
echo "<br>关键词:".$result[$j]."可能没有出现抱歉***!"."\n";
}
?>
不加上urlencode会出现如下问题:$url = "http://you.video.sina.com.cn/pg/search/iaskSearch.class.php?key=’Chinese‘ 而不是:"Chinese Democracy",为此最好每次涉及到url的时候加上urlencode.
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/1136/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表