PHP bir web sayfası dizeyi maç nasıl?

2 Cevap php

We can easily check for a match in a string

if (preg_match("/happy/i", "happy is he who has ")) {
    echo "match found.";
} else {
    echo "match not found.";
}
?>

Ama nasıl bir web sayfası maçın oluşumu için kontrol edin veya bir url verilen nasıl?

EDIT:

How to use Regex to find if a specific string exists within a webpage? I am able to extract all the information and display it using the code given in one of answers.

2 Cevap

Rodolphie öncede söylediğim gibi, cURL kullanarak uzaktaki bir sayfasını almak için en iyi yoldur. Eğer gerçekten metin bir dize olup olmadığını kontrol etmek regexpi kullanmanız gerekmez, bu onu yapacağız:

if (strpos($urlContents, $needle) !== FALSE) {
  echo "match found";
}

Sen kullanabilirsiniz file_get_contents

Düz php.net den

<?php
    $homepage = file_get_contents('http://www.example.com/');
    echo $homepage;
?>