如何在php if语句中使用多个路径

<?php if (preg_match('/\/contact\//', $_SERVER['REQUEST_URI']) === 1): ?>
<a href="/">link</a>
<?php endif; ?>

I'm trying to add multiple folders into the same statement like /contact/ and /news/, so the content inside the statement will appear in both folders.

I tried (preg_match('/\/contact\//', '/\/news\//', $_SERVER['REQUEST_URI']), but it returned errors.

What am I doing wrong?

You can use A | (OR) operator in regexp.

<?php if (preg_match('/\/(contact|news)\//', $_SERVER['REQUEST_URI']) === 1): ?>

That's not how preg_match works. First argument is REGEX and the second one is a subject. Use regex | operator

<?php if (preg_match('/\/(contact|news)\//', $_SERVER['REQUEST_URI']) === 1): ?>
   <a href="/">link</a>
<?php endif; ?>