我正在运行在每个页面上加载main.php文件的网站,它有数千页。每个页面网址都不同,例如
mywebsite.com/United-Kingdom.php
和
mywebsite.com/United-Stats-of-america.php.
每个页面都有唯一的页面标题,由PHP从数据库加载,
(<h4 style="font-size:20px;color:#148ADB;"><?php echo $cityname['country']; ?>Information</h4>
)。
我想用网址或页面标题自动更改标题jpg图像,例如,如果用户使用联合王国网址,则应在标题上加载/images/country/united-kingdom.jpg并且当用户打开美国统计数据网页时应该在标题上加载图像/images/country/united-stats.jpg。
我怎样才能实现这个目标?
= now()按票价排序&#34;); $ ARR1 = mysql_fetch_array($ SEL1); ?&GT;
<div id="content-top-txt" style="height:auto">
<div id="content-top-inner1">
<div id="content-top-txt-inner1" style="height:auto">
<div class="content">
<h4 style="font-size:20px;color:#148ADB;"><?php echo $cityname['country']; ?>specials</h4>
<p style='text-align:justify; font-size:13px; color:#3c3c3c;'>
<strong style="text-transform:uppercase;color:#148ADB;"><?php echo $cityname['country']; ?></strong> with choice of range prices think of comfort for lesser cost<strong style="text-transform:uppercase"><?php echo $cityname['country']; ?></strong> starts from <?php
$tempcode=$arr1['des_code'];
$stemp=mysql_query("SELECT * FROM cities_var WHERE code='$tempcode'");
$temp=mysql_fetch_array($stemp);
if($temp['code']=='')
{
?>
<strong><?php echo $arr1['des_name'];?> (<?php echo $arr1['des_code']; ?>) </strong>
<?php
}
else
{
?>
<a href="<?php echo $temp['url'] ?>" target="_blank"><strong><?php echo $arr1['des_name'];?> (<?php echo $arr1['des_code']; ?>) </strong></a>
<?php
}
?>
@ <strong>£<?php echo $arr1['fare']; ?></strong> with & table below<?php echo $arr1['des_name'];?> & other cities in <strong style="text-transform:uppercase"><?php echo $cityname['country']; ?></strong> About<strong>UK</strong>.General information About <strong style="text-transform:uppercase"><?php echo $cityname['country']; ?></strong>call @ 123456789 or use <a href="../../form.php">Form</a> or email:- <strong>Email@address.com</strong></p>
<p><?php echo $cvar['overview2']; ?></p>
<p>Note:-Prices given are excluding taxes</p>
</div>
<div id="content-top-inner2">
<div id="content-top-txt-inner2" style="height:auto">
<!-- slider start here -->
<div class="slider-main">
</div> <!-- slider end here-->
</div><!-- Content-top-txt-inner2 end-->
</div><!-- content-top-inner2 end here-->
</div><!--contaent-top-txt end here -->
</div><!--content-top end here -->
<div id="content-middle">
<div id="content-middle-txt">
<?php
include("../../files/lb1.php");
?>
<div class="content-middle-txt-right">
<?php
include("../../files/d-search-compare.php");
?>
</div>
<div style="clear:both"></div>
<div class="more"><p><span>Note : </span><?php //echo $sql_rec['note']; ?></p><p>paragraph text.</p>
</div> <!--content-middle-txt end -->
</div> <!--content-middle end -->
<div id="content-bottom">
<div id="content-bottom-txt">
<div id="bottom-all-box">
<?php
include("../../files/lb2.php");
?>
<div id="content-bottom-right">
<?php
include("../../files/rb1.php");
?>
</div>
</div>
<?php
/*
include("../../files/country-left-box3.php");
include("../../files/country-right-box1.php");
*/
?>
答案 0 :(得分:0)
我会将所有图像名称更改为PHP文件的确切页面名称。因此,例如,/united-kingdom.php
您的图片应命名为united-kingdom.jpg
。
使用相同的内容,您可以使用$_SERVER['REQUEST_URI']
获取您请求的当前页面网址。
现在,您可以使用当前页面名称定义图像。
$url= $_SERVER['REQUEST_URI'];
$imageName = substr($url, 0, strpos($imageName, "."));
变量$imageName
将包含united-kingdom
。
因此,您可以将图像定义为:
<img src="<?php echo $imageName; ?>.jpg" alt="" />
此代码未经过完整测试,只是为了让您了解如何处理它。