curl を使用して Web サイト (html コード) を解析しています:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/product.html");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$content = curl_exec($ch);
<span>
今、私は特定のものを見つけたいと思っています。<a>
タグにはhref
パラメータが含まれています。このパラメータ ( [eventUid]=22
) を preg match で見つけることはできますか? 22
データベースから取得した (id) を PHP を使用して変数に保存したいと考えています。
例:
<span><a title="mytitle" href="http://example.com/products.html?tx_example_pi1[eventUid]=22">example</a></span>
if (preg_match('@((https?://)?([-\w]+\.[-\w\.]+)+\w(:\d+)?(/([-\w/_\.]*(\?\S+)?)?)*)@', $content, $matches)) {
echo $matches[2];
} else {
echo 'Nothing found!';
}
現時点では、この preg 検索のリンクしか見つかりませんでした。