从远程iframe中查找和替换html内容

时间:2014-03-24 19:03:34

标签: php html regex iframe

从远程主机中提取捕获的iframe代码。

  <div class="ad-title">
                        <span class="pointer" onclick="window.open('surfv.php?view=surfer&f=1&t=f97e5cec351c254254c290577e6a&p=78r254sfsv46s224&u=1','_blank');">Link1 Name</span>  
                    </div>

        <p class="adimg"><img src="http://domain.com/banner_7.png"  style="max-height:50px; max-width:200px;;border:0px;"/></p>
                               <div class="ad-content">



        <table cellpadding="5" width="100%"><tr>
             <td valign="top"><span style="font-family:  Verdana, Sans-serif; font-size:13px; ">Add title</span></td>
             </tr>
             </table>
                    </div>
                        赚                                             $                                         0.0005                         

我已经捕获了远程iframe并阅读了代码。

$homepage = file_get_contents('http://remotehost.com/iframe.php');
echo $homepage;
?>

代码的摘录如上所示

我想抓拍

surfv.php?view=surfer&f=1&t=f97e5cec351c254254c290577e6a&p=78r254sfsv46s224&u=1

Link1名称 $ 0.0005

从此框架中按以下格式将它们放入新表中。 新链接=`http://mywebsite.com/surfv.php?view=surfer&f=1&t=f97e5cec351c254254c290577e6a&p=78r254sfsv46s224&u=1

NewLink Title= Link1 Name
Price= $0.0005
--------------

感谢您的帮助

1 个答案:

答案 0 :(得分:2)

<?php
function gsb($string, $start, $end)
{
    $string = " " . $string;
    $ini    = strpos($string, $start);
    if ($ini == 0)
        return "";
    $ini += strlen($start);
    $len = strpos($string, $end, $ini) - $ini;
    return substr($string, $ini, $len);
}
$homepage = file_get_contents('http://remotehost.com/iframe.php');
$link="http://mywebsite.com/".gsb($homepage,"window.open('","'");
echo $link;