Jump to content


Photo

if ($link == ??)


  • Please log in to reply
3 replies to this topic

#1 B.O.V.N

B.O.V.N
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 27 August 2006 - 11:43 PM

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.

My problem
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.co...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:

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

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.co...Site440.dbp.asp which will link to a non-existing site. It should be http://www.mysite.co...548_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.


#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 August 2006 - 12:08 AM

this kind of works but i need it to ignore the first _ get me.

try

<?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;
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 radar

radar
  • Members
  • PipPipPip
  • Advanced Member
  • 645 posts
  • LocationSLC

Posted 28 August 2006 - 12:13 AM

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


#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 28 August 2006 - 12:16 AM

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

<?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;
}

?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users