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 ?>

ブラケットと「Page」という単語を「Number」という文字列から、matches5 変数と呼ばれる文字列から削除しようとしています。

このコードを下で使用するたびに、空白が表示され、非常に混乱します。PHP 2番目のコードに不慣れな人を助けてください

<?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;

2 番目の例 (良い)。

$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 に答える