Search code examples
phppreg-matchdetectsearch-multiple-words

Detect multiple words with preg_match in php


i want detect some words when read first line file.

this my code

    $open  = @fopen($file,"r");
    $line  = @fgets($open);
    $close = @fclose($open);
    return preg_match('/\<\?php/',$line);

words for detect

"<?php","<?","<html>"

i do not know how do it with multiple words, any help please


Solution

  • http://php.net/manual/en/regexp.reference.alternation.php - alteration can help you. In your particular case, you have to extend your regexp as the following:

    return preg_match('/^<(?:\?(?:php)?|html>)/',$line);