PHP卷曲和字符串替换

时间:2017-06-01 20:03:21

标签: php regex curl preg-replace

我有很多年前购买的这个代码对我来说很好用:

<?
$theLocation="http://www.ampolinc.com/wycieczki.php";
$baseURL="http://ampolinc.com/"; 

preg_match("/^(https?:\/\/)?([^\/]*)(.*)/i", "$theLocation", $matches);
$theDomain = "http://" . $matches[2];
$page = $matches[3];

$fd = fopen($theDomain.$page, "r");
$value = "";
while(!feof($fd)){
    $value .= fread($fd, 4096); 
}
fclose($fd);

// replace with your unique start point in the source of the HTML page
$start= strpos($value, "<td width=\"694\" bgcolor=\"#FFFFFF\">");  
// replace with the unique finish point in the source of the HTML page 
$finish= strpos($value, "<table width=\"709\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:5px 0px 0px 167px;\"><tr><td>");  
$length= $finish-$start;

$value=substr($value, $start, $length);

$value = eregi_replace( "plan", "print", $value );   .
$value = eregi_replace( "fd9b1a", "ffffff", $value );

$FinalOutput = preg_replace("/(href=\"?)(\/[^\"\/]+)/", "\\1" . $theDomain . "\\2", $value);
echo "<base href=\"$baseURL\">"; // sets the remote site as the base, so that relative links are fixed.
echo "<font style=\"font-size: 9pt\">";
echo $FinalOutput; //prints it to your page
flush (); //force output faster
echo "</font>";

?>

但是由于eregi_replace()在PHP 7中已被弃用和删除,因此它不再起作用了

我不是编码员所以当我试图让它工作时我只能显示内容,但我可以;更换页面内的字符串。

http://pentiger.com/download.php

修复我需要替换单词的链接:  “计划”到“打印”

这是我现在使用的代码

<?php
$baseURL="http://www.ampolinc.com/"; 
$curl = curl_init('http://www.ampolinc.com/wycieczki.php');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);

$page = curl_exec($curl);

if(curl_errno($curl)) // check for execution errors
{
    echo 'Scraper error: ' . curl_error($curl);
    exit;
}

curl_close($curl);


$regex = '/<td width=\"694\" bgcolor=\"#FFFFFF\">(.*?)<table width=\"709\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\" style=\"margin:5px 0px 0px 167px;\"><tr><td>/s';


if ( preg_match($regex, $page, $list) ) {    
    echo "<base href=\"$baseURL\">";
    echo "<font style=\"font-size: 9pt\">";
    echo $list[0]; //prints it to your page
    echo "</font>";       
} else 
    print "Not found"; 
?>

我可以在echo“”之前替换$ list中的字符串吗?

由于

0 个答案:

没有答案