我怎样才能在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/*'.

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; ?>
if (preg_match('/\/posts\//', $_SERVER['REQUEST_URI']) === 1)

or

if (strpos('/posts/', $_SERVER['REQUEST_URI']) !== false)