Jump to content

Archived

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

B.O.V.N

if ($link == ??)

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.

Share this post


Link to post
Share on other sites
this kind of works but i need it to ignore the first _ get me.

try

[code]
<?php

$url="http://redarrow.com?s_de_123456";

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

echo " site there in link";

}elseif($url=str_replace("_","_site",$url)){

echo $url;
}

?>
[/code]

Share this post


Link to post
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..

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.