duanmeng2842 2015-11-03 23:33
浏览 90
已采纳

在php中使用preg_match检测多个单词

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

  • 写回答

1条回答 默认 最新

  • dqnrk44682 2015-11-04 00:29
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了