- 786 名前:nobodyさん mailto:sage [2009/08/10(月) 17:24:39 ID:???]
- テキストファイルからURLを抽出するphpを書きたいのですが、
$source (元のテキストファイル) $result (URLリスト) とします。 phpspot.net/php/man/php/function.preg-match-all.html ここを参考に以下のコードを書きました。 // $pattern = '/http:\/\/[a-z0-9\/\-_\.]+/i'; // $pattern = '/(?:")?(http:\/\/[^\s"]+)/'; $pattern = '/^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/'; preg_match_all( $pattern, $source, $maches ); fputs($pointer, count($matches[0])); fputs($pointer, "\n"); for ( $i=0; $i< count($matches[0]); $i++ ) { fputs($pointer, $maches[1][$i]); } 色々パターンを変えてやってみても、結果はいつも0(何もマッチしない)です。 これ以外の方法でも構わないので、テキストからURLリストを作る方法を教えてください。 よろしくお願いします。
|

|