根据URL生成PHP页面

根据URL生成PHP页面

问题描述:

Apologies if this has been asked before. Basically I did a search on Google and found nothing relevant.

I want to be able to create a template and use that template to generate dynamic content based on the URL.

So if I go to 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"

so if I go to 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

I hope that is clear

如果之前已经询问过此道歉。 基本上我在Google上进行了搜索,没有发现任何相关内容。 p>

我希望能够创建模板并使用该模板根据URL生成动态内容。 p> \ n

所以,如果我去mydomain.com/mypage.php?img=source

nn

它应该生成我的mypage.php模板并更改img或任何其他内容源 对于“来源” p>

所以,如果我去mydomain.com/mypage.php?img=bird

nnn

我的mypage.php会显示 并且需要更改其变量的图像或其他内容将输出鸟 p>

我希望这是明确的 p> div>

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.
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. 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