Jump to content

eregi_replace to find id & url?


yarito

Recommended Posts

Hi PHPFreaks,

 

I've got this little function I wrote which converts links in my custom-built CMS. By using the Id of the page to link to, I can easily make an internal link to my own website, such as:

 

A link:

<link=1>this is a link</link> 

 

My function:

function convert_Links($content) { 
        $pattern='(<link=)([0-9]{0,5})(>)'; 
        $replacement='<a href="/index.php?id=\2">'; 
        $pattern2='</link>'; 
        $replacement2='</a>'; 
        $content=eregi_replace($pattern2, $replacement2,eregi_replace($pattern, $replacement, $content));     
        return $content; 
    } 

 

 

which creates a nice link to: index.php?id=1 or whatever.

 

However, I've recently changed to showing my urls using Mod-rewrite, so it would now show as:

 

/products/product-number-5/1

(where the '1' on the end is the page Id)

 

Is there any way to get this url using my function, rather than just the Id?

To do this I'd need to extract the id, call another function to look up this page's url, then pass that back to the function.

 

Help! I've been stuck on this for 6 months...

 

 

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.