0
<?php 
$file = file_get_contents("http://www.mywebsite.net/folder/indexhtml.asp");
preg_match_all('~<td width="23%" height="23" align="right">(.*?)</td>~is',$file, $matches5);
print implode("\n", $matches5[0]);       //This prints out (Page: 889) on website ?>

我正在尝试从名为matches5变量的字符串中删除括号和带有“Number”的单词“Page”

每次我在下面使用这段代码时,它都会显示空白,这让我很困惑。请帮助我,因为我是 PHP Second 代码的新手

<?php

$file = file_get_contents("http://www.mywebsite.net/folder/indexhtml.asp"); 
preg_match_all('~<td width="23%" height="23" align="right">(.*?)</td>~is',$file,  $matches5); 
$result = preg_replace('/(?<=^| ).(?=$| )/sm', '', $matches5); 
print implode("\n", $result[0]);

?>
4

1 回答 1

0

第一个例子(坏):

$array = array("");
$replace = array("");
// Please put the maximum number this (Page: maximum)
for($i = 1; $i <= 1000; $i++)
{
array_push($array, "(Page: $i)");
// Put your replace string this or leave blank
array_push($replace, "I am replaced :)");
}

$file = 'I am (Page: 129) this is test.';

$new_string = str_replace($array, $replace, $file);

echo $new_string;

第二个例子(好)。

$file = 'I am (Page: 129) this is test.';

$new_string = preg_replace('(Page: ([0-9]+))', "", $file);
$new_string = str_replace("()", "", $new_string);

echo $new_string;
于 2013-08-29T20:33:32.663 回答