基于网页内容数据采集 PHP开发学习笔记

时间:2023-03-09 22:57:44
基于网页内容数据采集 PHP开发学习笔记

jQuery数字的截取:

str.toFixed(num);//小数的截取

toFixed()

<script type="text/javascript">

 var aa = 2.3362;  

document.write(aa.toFixed(1)); // 2.3 
document.write(aa.toFixed(2)); // 2.34  
document.write(aa.toPrecision(2)); // 2.3 
document.write(aa.toPrecision(3)); // 2.34  
document.write(Math.round(aa * 10) / 10); // 2.3 
document.write(Math.round(aa * 100) / 100); // 2.34  
</script>

js:parseInt(num) ;//丢弃小数部分,保留整数部分

http://blog.****.net/robinpipi/article/details/6588315

php抓取网页内容:

<?php
$url ="https://licai.taobao.com/json/getFundProductByCode.html?fund_code=000962";
$contents = file_get_contents($url);
?>

正则表达式匹配筛选抓取的内容:

preg_match('/[0-9]{1,2}.[0-9]{4}/',$contents,$source_worth);

php字符串替换

$time=“2015-09-20”;
$time=str_replace('-','',$time);
//20150920

 php字符串截取

string substr ( string $string , int $start [, int $length ] )
返回字符串 string 由 start 和 length 参数指定的子字符串。