|
300积分
想抓取目标网页日元对人民币汇率这个数值并生成JS,我改的代码输出只有0.0034。会的帮忙改下,谢谢。
- <?php
- $arr = file("https://www.huilv.cc/JPY_CNY/");
- if($arr){
- foreach($arr as $a){
- if(strchr($a,"<div class=dollar_two><span class=back>")){
- $a = str_ireplace("<div class=dollar_two><span class=back>","",$a);
- $a = str_ireplace("</span></div><div class=clear>","",$a);
- $b = $a+0.0034;
- echo $b ;
- $content = " var rate = $b;
- document.writeln('$b');";
- $fp = fopen ('ka'. '.js',"w");
-
- if (fwrite ($fp,$content)){
- //格式是.int fwrite(int fp(文件名), string string(内容),
-
- fclose ($fp);//函数用来关闭已经打开的文件的指针 fp。
-
- die ("");
- } else {
- fclose ($fp);
- die ("");
- }
- echo ($content);
- break;
- }
- }
- }
-
-
- ?>
复制代码 |
|