4,251
社区成员
发帖
与我相关
我的任务
分享
js:
$(document).ready(function(){
function yesShow(){
url = '/index.php/home/Index/showNews' + '/univ_name/'+univ_name;
htmlobj = $.ajax({
type:"POST",
url : url,
async : false
});
alert(htmlobj.responseText);
$("#popNew").html(htmlobj.responseText);
}
window.onload=yesShow;
});
php:
public function showNews($univ_name){
$univ_name=$_GET['univ_name'];
$url = "http://www.sogou.com/web?query=".$univ_name."&ie=utf8";
$contents = file_get_contents($url);
//汉语输出
echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>";
//起始字符位置
$start_ch=strpos($contents,'<ul class="str-ul-list new-ul-list">');
//结束字符为止
$end_ch=strpos($contents,'</ul>',$start_ch)+5;
//新闻相关字符串
$new_str=substr($contents, $start_ch,$end_ch-$start_ch+1);
if ($new_str&&$contents&&$start_ch&&$end_ch){
echo $new_str."<br/>";
}
else echo "<center>"."没有搜到相关新闻"."</center>";
}