0

SOLUTION

$path = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$feedtitle = str_replace(" ", "", $feedtitle);
$feedtitle = strtolower($feedtitle);
$path = substr($path, 0, strrpos($path, "/"));
$feedlink = "http://" . "$path" . "/"  . "$feedtitle" . '.xml';

PROBLEM

I am trying to generate a name for an rss feed from another field (feed title). In my query I have :

$path = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$feedtitle = str_replace(" ", "", $feedtitle);
$feedtitle = strtolower($feedtitle);
$feedlink = "$path" . "$feedtitle" . '.xml';

If feedtitle is my rss feed, $feedlink will have the value myrssfeed.xml so that part of the code works but I'm having problems with the path. Instead of writing the current path the above writes the current path & the name of the current file! e.g. if the script I'm using for this is named feedlink.php the path that is stored in the $feedlink variable is :

mywebsite.com/mydir/feedlink.phpmyrssfeed.xml

How do I remove the name of the script?

2 Answers 2

1

With the str_replace() function

 $feedlink = str_replace("feedlink.php", "",  $feedlink);
Sign up to request clarification or add additional context in comments.

1 Comment

Used a combination of your code and Kevin's to resolve it. Thanks.
1

Assuming that you requested the site as mywebsite.com/mydir/feedlink.php you should consider removing everything past the last / and then add your filename to that:

$path = substr($path, 0, strrpos($path, "/") + 1);

1 Comment

Using that gives : mywebsite.com/mydirmyrssfeed.xml so it's removing the / after the dir.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.