Adding predefined text to webpage

Not sure if that title encapsulates what I am trying to say, but basically I have the script that can work if the page is on the root of the domain with htaccess, but not in a subfolder.

I just want an easy way to have it so if I type in a domain name such as: www.mysite.com/subfolder/hi that it will put “hi” in the page where I want.

The code I had was something like:

[php]$item = $_GET[‘item’];
if (!$item) $item = “test”;

$item2 = str_replace("-", " ", $item);[/php]

then in the page it would have

[php]

<?=$item2;?>[/php]

but I cant get it to work. help please!

Hmmm… Your code you posted was replacing a dash with a space… Do not know what this does for your question! So, let’s guess…

You want to type in a URL and you want to post the last segment of the URL on a page?
Is that what you really want? If so, you can use the “directory” function of PHP.

Something like this:
$item2 = end(explode(’/’, $item));

This is basically:
$parts = explode(’/’, $item); //explodes or divides $item into array of items separated by “/”
$item2 = end($parts); // selects last item in array…

Hope that helps… Good luck…

Sponsor our Newsletter | Privacy Policy | Terms of Service