Jump to content

Extracting a number from an url


affpro1234

Recommended Posts

I have converted a database from one script i have to be used for another script.

The url stucture of both scripts is different and I need to create a 301 redirect script to run on the new site to send the old linked pages to the new url structured pages.

The new converted database holds the new urls in it and I can call them using an article id number which is the same number included at the end of the old url (ie http://www.sitename.com/Articles/title-of-article/1234)

 

I am trying to extract the number from the old url, but am having difficulty...very newbie here.

 

here is the code that I have so far:

function getInfo(){
    $url = rtrim($_SERVER['REQUEST_URI'], '/');
    $urlParts = explode('/', $url);
    $lastPart = end($urlParts);
    }

$articles = $this->getArticles("article_id = ".intval(getInfo()),'',1);
$article = $articles[0];

header("Status: 301 Moved Permanently", false, 301);
header("Location: $article->url");
exit;

 

All comments and any help would be appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/110507-extracting-a-number-from-an-url/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.