douhua9726 2013-06-13 03:04
浏览 16
已采纳

我怎样才能在HTML中使用通配符PHP异常

When I use something like:

<?php if ($_SERVER['SCRIPT_NAME'] == '/index.html'): ?>
// Only Show in Index
<?php endif; ?>

to set something to only display in the specified page. Is there a way to wildcard the pages? For example, setting it to only display on a wildcard of pages in a directory '/posts/*'.

  • 写回答

2条回答 默认 最新

  • dongzichan2886 2013-06-13 03:08
    关注

    Use preg_match(). The documentation can be found here.

    Example of usage:

    <?php if (preg_match('%^/index.html%',$_SERVER['SCRIPT_NAME'])): ?>
    // Only Show in Index
    <?php endif; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?