Php include然后抓取当前URL的结尾并将它们组合起来

I am trying to include a file based on the current page of a URL the user is on.

The files are stored in /includes/ in all cases and on the same domain.

If the current URL the user is on is for example:

www.website.com/page/text_i_want.php?info=tree

<?php $url = curPageURL();?><?php include ("{$_SERVER['DOCUMENT_ROOT']}/includes.'/'.$id = substr( $url, strrpos( $url, '/' )+1"  ?>

This is what I have but even if that did work, it would't remove a everything after and including the .php and add .txt to the end

I just want to grab text_i_want from the end of the URL (not including the dynamic part) and add .txt to the end so effectively I am including:

{$_SERVER['DOCUMENT_ROOT']}/includes/text_i_want.txt

I keep getting an ';' error and syntax error, unexpected T_ECHO with what I have.

Update:

<?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/' . basename($_SERVER['REQUEST_URI'], '?'.$_SERVER['QUERY_STRING']); ?>

That code grabs the file name at the end of the URL, which is what I want. I am just unsure how to replace .php with .txt

Solved: (But unsure how efficient or neat this is, but it works)

I didn't really know what I was doing but somehow I've managed to mix together @SamOwl's code and one I found and edit them slightly to achieve the result In wanted:

<?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/' . basename($_SERVER['REQUEST_URI'], 'php?'.$_SERVER['QUERY_STRING']) . 'txt'; ?>

I think this is what you need:

<?php include $_SERVER['DOCUMENT_ROOT'] . '/includes/' . basename(__FILE__, '.php') . '.txt'; ?>

UPDATE

According to your update, try $_SERVER['REQUEST_URI'] PHP Docs says: "The URI which was given in order to access this page; for instance, '/index.html'".

If this is not what you want, give a read on PHP Server Variables