将完整的tumblr页面集成到网站中

时间:2012-02-22 22:06:25

标签: php javascript jquery html tumblr

我目前正在使用此代码:

  

$ blog = file_get_contents(“http://powback.tumblr.com/post/”。$ post);   echo $ blog;

它有效。但是tumblr添加了一个脚本,每次输入密码字段时都会激活该脚本。所以我的问题是:

我可以使用“file_get_contents”删除某些部分吗? 或者删除上面的所有内容 一切都会奏效! 谢谢您的帮助!

(我可能会杀死整个div,所以它根本不会加载吗?)

1 个答案:

答案 0 :(得分:0)

您可以尝试这样的方法,假设您要删除的div具有特定的ID和/或类:

$blog= file_get_contents("http://powback.tumblr.com/post/" . $post); 
$blog = preg_replace('!<div\s+id="div-id"\s+class="div-class">.*?</div>!is', '', $blog);
echo $blog;

我在(http://stackoverflow.com/questions/1114916/how-can-i-remove-an-html-element-and-its-contents-using-regex)中发现的帖子指出,如果有的话是一个嵌套的div,这将失败。

无论如何,preg_replace或regex是你最好的选择。

相关问题