简体   繁体   English

根据URL生成PHP页面

[英]Generate PHP page based on URL

Apologies if this has been asked before. 抱歉,是否曾经有人问过。 Basically I did a search on Google and found nothing relevant. 基本上,我在Google上进行了搜索,但没有发现任何相关信息。

I want to be able to create a template and use that template to generate dynamic content based on the URL. 我希望能够创建一个模板并使用该模板根据URL生成动态内容。

So if I go to mydomain.com/mypage.php?img=source 因此,如果我转到mydomain.com/mypage.php?img=source

It should generate my mypage.php template and change the img or any other content source to that of "source" 它应生成我的mypage.php模板,并将img或任何其他内容源更改为“源”

so if I go to mydomain.com/mypage.php?img=bird 所以如果我去mydomain.com/mypage.php?img=bird

my mypage.php will show and the image or other content whose variable needs to be changed will output bird 我的mypage.php将显示,需要更改其变量的图像或其他内容将输出bird

I hope that is clear 我希望这很清楚

Try this: 尝试这个:

if ($_GET['img'] == 'source') {
    // do stuff
} elseif ($_GET['img'] == 'bird') {
    // do other stuff
} else {
    // do stuff if 'img' is not set or is empty
    // or just none of the above
}

Ok, I keep adding stuff to this! 好的,我一直在添加东西!

<?php
    if(isset($_REQUEST['img'])) {
    }
    else {
        $_REQUEST['img'] = "false";
        $image = "false";
    }
    $image = $_REQUEST['img'];
    $image = strtolower($image);
    if ($image == 'false'){
        $content = 'no image specified';
    }
    else{
        $content = print '<img src="images/'.$image.'.jpg">';
    };
?>

To change the image size, you could just add a width and height before src . 要更改图像大小,您可以在src之前添加宽度和高度。
Then, to print the image, all you have to do is add this where you want it to show: 然后,要打印图像,您所要做的就是将其添加到想要显示的位置:

<?php print $content; ?>

well. 好。 apparently in order to achieve what i wanted, i need to use MYSQL so that the information can be retrieved via a query. 显然,为了实现我想要的功能,我需要使用MYSQL,以便可以通过查询检索信息。 none of the other answers met my requirement. 没有其他答案符合我的要求。

this website helped a lot with a tutorial which i was able to tinker with and achieve my requirement -> http://www.vdesignourweb.com/cmsphpsqlb/cms_intro.html 这个网站提供了一个教程,可以帮助我达到并满足我的要求-> http://www.vdesignourweb.com/cmsphpsqlb/cms_intro.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM