<?php if (preg_match('/\/(contact|news)\//', $_SERVER['REQUEST_URI']) === 1): ?>
<a href="/">link</a>
<?php endif; ?>
Is there a way I can also specify a single page such as /index.html
in a regex specifying folders in a php if
?
<?php if (preg_match('/\/(contact|news)\//', $_SERVER['REQUEST_URI']) === 1): ?>
<a href="/">link</a>
<?php endif; ?>
Is there a way I can also specify a single page such as /index.html
in a regex specifying folders in a php if
?
Try the below :
<?php if (preg_match('/\/(contact|news)\/index\.html/', $_SERVER['REQUEST_URI']) === 1): ?>
<a href="/">link</a>
<?php endif; ?>
UPDATE
Based on your comment below this is the code that should work :
<?php
// you can add .* after index\.html you want to match index.html with get variables
echo preg_match('/\/(index\.html.*|contact\/.*|news\/.*)/','/index.html');
// or just make it strict to match only index.html
echo preg_match('/\/(index\.html|contact\/.*|news\/.*)/','/index.html');
echo '<br>';
echo preg_match('/\/(index\.html|contact\/.*|news\/.*)/','/contact/blablabla');
echo '<br>';
echo preg_match('/\/(index\.html|contact\/.*|news\/.*)/','/news/blablabla');
?>