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
Share on other sites

You're missing only one thing:

 

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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