Hi. We have this: <?php $uri = $_SERVER['REQUEST_URI']; if ( strpos($uri,'members') !== false ) { echo '<link href="cssfile-a.css" rel="stylesheet" type="text/css" />'; } else { echo '<link href="cssfile-b.css" rel="stylesheet" type="text/css" />'; } ?> Which makes the browser insert the cssfile-a file if the word "members" is in the url string. In other case, cssfile-b.css. The question is that I would like it in the negative way: if the word "members" is in the url string, then DO NOT insert the cssfile.a file, and INSERT IT in all the other cases. Is this possible? I have set it like this: <?php $uri = $_SERVER['REQUEST_URI']; if ( strpos($uri,'members') !== false ) { else { echo ''; } } else { echo '<link href="cssfile-a.css" rel="stylesheet" type="text/css" />'; } ?> It works. But I think that this is not valid PHP. I mean the correct way to do it. Thanks very much for your help.
You mean like this? <?php $uri = $_SERVER['REQUEST_URI']; if ( strpos($uri,'members') !== false ) echo '<link href="cssfile-a.css" rel="stylesheet" type="text/css" />'; ?> PHP: Sorry, I'm a bit confused by your question.
I think is not equal is != or you can try this.. <?php $uri = $_SERVER['REQUEST_URI']; if(!strpos($uri,'members')){ }else{ echo '<link href="cssfile-a.css" rel="stylesheet" type="text/css" />'; } ?> Code (markup):
I think it is a single line solution echo strpos($_SERVER['REQUEST_URI'],'members') ? '' : '<link href="cssfile-a.css" rel="stylesheet" type="text/css" />'; Code (markup):
strpos returns the index of the found string. Therefore != isn't safe if the string is found at index 0 (the beginning of the string). You need to use the strict comparison with this function. Change your original code to this: <?php $uri = $_SERVER['REQUEST_URI']; if ( strpos($uri,'members') === false ) { echo '<link href="cssfile-a.css" rel="stylesheet" type="text/css" />'; } ?> PHP: