Jump to content

if ($link == ??)


B.O.V.N

Recommended Posts

Hello.

I am now done with my comment function, created to grant the visitors the possibility to comment an article. But there is one thing that I cannot solve (Note: It has been three weeks since I first started to use PHP) so therefore I thought that somebody might be so kind to help me with my problem.

[b]My problem[/b]
It is in my index.php where I have some previews of articles and other stuff, but most importantly in this issue the function to see the latest 3 comments. And in these boxes I have created a link that will direct the visitor to the certain HTTP adress where the commented article is located. Now the pop-up box where you comment an article has a function that will fetch the article ID of the article and create a comment site with the same ID. Here is a typical link to an article: http://www.mysite.com/articles/200604/21/20060421151548_Site440/20060421151548_Site440.dbp.asp

Don't ask why the article's are made in ASP and the comments in PHP :) Long story :)

Anyway the link that will link to its mother (the articles HTTP) is created in the way that you can see in Listing 1:

[b]Listing 1[/b]
[code] $link = 'http://www.mysite.com/articles/'.substr($article_id, 0, 6).'/'.substr($article_id, 6, 2).'/'.substr($article_id, 0, 22).'/'. $article_id;[/code]

So in other words the ID of the article is for an example 20060421151548_Site440.dbp.asp and the function above will make that the link will automatically link to the correct folder/sub-folder etc. But the problem is this: most of the time the article ID does not include "Site" and is therefore only; 20060421151548_440.dbp.asp. But my code will therefore generate the following link: http://www.mysite.com/articles/200604/21/20060421151548_440.dbp/20060421151548_Site440.dbp.asp which will link to a non-existing site. It should be http://www.mysite.com/articles/200604/21/20060421151548_440/20060421151548_440.dbp.asp

But how do I manage to do this without f***ing with the links that has Site in them?

Thankful for help.
Link to comment
Share on other sites

I thought he could just do something like this cause i found 2 differences in the links he provided...

#1
$link = ereg_replace('.dbp\\', '\\', $link);
$link = ereg_replace('_Site', '', $link);

I'd think that using those 2 lines of code would format the links to the way the bottom one looks.. i may be wrong but thats what i'd figure..
Link to comment
Share on other sites

got it lol.......................

[code]
<?php

$url="http://www.mysite.com/articles/200604/21/20060421151548_440/20060421151548_440.dbp.asp";

if(eregi("_site",$url)){

// do somethink as the link is correct
echo $url;

}elseif($url=eregi_replace("_[0-9]","_site",$url)){

//correct the link then so somethink.
echo $url;
}

?>
[/code]
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.