1

約 2000 の Web サイトを含む csv ファイルがあり、各サイトの file_get_contents を実行するスクリプトがあり、電話番号を探します。

私のプレグマッチが機能していません!!?? 正確な数字の文字列 800-885-7505 を見つける必要があります

私は試した:

preg_match('/^800-885-7505$/', $page, $matches);

しかし、うまくいきませんでした....理由を教えてもらえますか?ありがとうございました!

私は試した:

<?
$file = fopen('file.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
  //$line is an array of the csv elements
  $page = file_get_contents("http://www.".$line[0]);
 preg_match('/800-885-7505/', $page, $matches);
 echo "http://www.".$line[0]." = ".$matches[1] . "<br><br>";
}
fclose($file);
?>

この DID は機能します。ページ上の iframe を検索する同じスクリプトがあり、うまく機能します。

<?
$file = fopen('file.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
  //$line is an array of the csv elements
  $page = file_get_contents("http://www.".$line[0]);
  preg_match('/<iframe.*src=\"(.*)\".*><\/iframe>/isU', $page, $matches);
  if (($matches[1]!=="http://www.url.com/lmapp.html") && ($matches[1]!=="http://www.url.com/mc_NewApp2.html"))
  {echo "http://www.".$line[0]." = ".$matches[1] . "<br><br>";}
}
fclose($file);
?>

だから私がする必要があるのは、電話番号の正確なプレグマッチを取得することだけだと思った

4

1 に答える 1

1

以下を使用できます。

preg_match('/800-885-7505/', $page, $matches);

またはより速い:

if ( strpos('800-885-7505',$page) !== false )
于 2013-01-10T03:11:31.477 に答える