有PHP ASP双向高手没,进来看看
<?
header( "content-type:text/html; charset=gb2312 ");
$do=$_POST[ "query "];
$do=trim($do);
$do=strtolower($do);
$url= "http://www.baidu.com/word=$do ";
$a=file_get_contents($url);
$arr=explode( " <msg> ",$a);
$arr=explode( " </msg> ",$arr[1]);
$s=$arr[0];
if (strpos($s, "找到 "))
{
$s=str_replace( "恭喜! ", " ",$s);
exit( " <div id= 'do ' style= 'color:#F1AB41 '> $s <a href= 'javascript:markme(\ " ".trim(str_replace( "恭喜恭喜找到 ", " ",$s)). "\ "); '> 收藏 </a> </div> ");
}
if (strpos($s, "有误 "))
{
exit( " <div id= 'do ' style= 'color:#FF0000 '> ".$s. "或查询出错 <a onclick= 'this.parentNode.style.display=\ "none\ " ' href= 'javascript:requery(\ " ".trim(str_replace( "输入有误 ", " ",$s)). "\ "); '> 重新查询 </a> </div> ");
}
echo " <div id= 'do '> $s ";
$name=trim(str_replace( "155 ", " ",$s));
if (strpos($s, "155 "))
echo " <a href=\ "javascript:whois( '$name ', ' ".str_replace( ". ", " ",$name). " ');\ "> Whois信息 </a> <div id= ".str_replace( ". ", " ",$name). " style= 'display:none;width:400px; '> Loading... </div> ";
echo " </div> ";
?>
能把他转换成ASP.net吗?
主要是这几句
$do=$_POST[ "query "];
$do=trim($do);
$do=strtolower($do);
$url= "http://www.baidu.com/word=$do ";
$a=file_get_contents($url);
$arr=explode( " <msg> ",$a);
$arr=explode( " </msg> ",$arr[1]);
$s=$arr[0];
if (strpos($s, "找到 "))
{
$s=str_replace( "恭喜! ", " ",$s);
------解决方案--------------------这么点分
太每动力了 呵呵
string q = Request.Form[ "query "];
string url = "http://www.baidu.com/word= "+q.Trim().ToLower();
string content = get_file_content(url);
string[] ar = content.Split( " <msg> ");
string[] ar1 = ar[1].Split( " </msg> ");
if (ar1[1].IndexOf( "找到 ") > 0)
{
//找到
}
public static string get_file_content(string url)
{
System.Net.WebClient wc = new System.Net.WebClient();
return wc.DownloadString(url);
}
------解决方案--------------------$相当于定义string,int
trim相当于Trim();
strtolower相当于ToLower();
explode相当于Split();
strpos相当于IndexOf();
str_replace相当于Replace();
------解决方案--------------------split没有一个string参数的重载,因此你要在加一个参数:
s.Split( " <msg> ", StringSplitOptions.RemoveEmptyEntries);