duanjingwei7239 2015-03-17 18:00
浏览 59

PHP如何读取URL和修改内容

I want to read a url, like Google, and modify the HTML tag value.

$homepage = file_get_contents('http://www.google.com');
echo $homepage;

For example, after read google link, I want set the google search box value to hello word, something like <input type='text' value='hello world'/>

Then display the modified page.

How to do this in php, thank you very much

  • 写回答

1条回答 默认 最新

  • dqce48404 2015-03-17 18:11
    关注

    You would need to modify the content of $homepage variable. What file_get_contents does is store the content of the file as a string.

    So you would have to look up the textbox identifier and use a string function to add the value to the textbox.

    Afterwards you would echo the modified $homepage variable.

    Take a look into string functions here:

    http://www.w3schools.com/php/php_ref_string.asp

    And particularly into this:

    http://www.w3schools.com/php/func_string_substr_replace.asp

    If you want to see the string of code that you are actually working with put this at the beginning of your file:

    header('Content-type: text/plain');
    $homepage = file_get_contents('http://www.google.com');
    
    echo $homepage;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题