PHP-如果页面URL=”http://example.com/page,显示图像。否则,显示另一个图像
我有我的模板,我希望它显示一个特定的图像,如果你在特定的页面上,如http://example.com/test 如果您不在该页面上,那么我希望它显示另一个图像 我还希望它显示图像,如果你在任何子目录,如http://example.com/test/stuff 另外,是否有一种方法可以在同一代码中使用多个页面来实现这一点 很像PHP-如果页面URL=”http://example.com/page,显示图像。否则,显示另一个图像,php,url,if-statement,selection,Php,Url,If Statement,Selection,我有我的模板,我希望它显示一个特定的图像,如果你在特定的页面上,如http://example.com/test 如果您不在该页面上,那么我希望它显示另一个图像 我还希望它显示图像,如果你在任何子目录,如http://example.com/test/stuff 另外,是否有一种方法可以在同一代码中使用多个页面来实现这一点 很像 if page = example.com/test then display testimg.jpg if page = example.com/archive t
if page = example.com/test then display testimg.jpg
if page = example.com/archive then display archive.jpg
else, display defaultimg.jpg
谢谢 U还可以使用strpbrk函数获得更紧凑的代码:>PHP5
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if ( strpos($url, 'test') !== false ) {
echo('<img src="image_path/testimg.jpg">');
}
elseif ( strpos($url, 'archive') !== false ) {
echo('<img src="image_path/archive.jpg">');
}
else {
echo('<img src="image_path/defaultimg.jpg">');
}
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if ( strpbrk($url, 'test') ) {
echo('<img src="image_path/testimg.jpg">');
}
elseif ( strpbrk($url, 'archive') ) {
echo('<img src="image_path/archive.jpg">');
}
else {
echo('<img src="image_path/defaultimg.jpg">');
}
相关人员:谢谢,但我没有回答我的问题。仍然不知道如何用它实现图像。我对PHP还很陌生,仍在努力学习诀窍。请考虑发布您的尝试代码。请参阅。函数strpos可能返回布尔值FALSE,但也可能返回计算结果为FALSE的非布尔值。有关更多信息,请阅读布尔值部分。使用===运算符测试此函数的返回值。