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
https://forums.phpfreaks.com/topic/65334-eregi_replace-to-find-id-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.