Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

making [link] tags for a web forum.

Status
Not open for further replies.

mrfundeath

Programmer
Sep 5, 2001
12
US
How would i go about making [link][/url] tags work for a PHP web forum i am making using string replacement functions?
everything else for the forum i can do ( bold, colors, smileys etc.)
but the link tag i am having problems.
For instance if people leave off the [/url] or
just do [link=http://mysite.com
and forget to leave the last ']' off
all hell breaks loose.
Need help!
 
You need to be sure that both the starting AND ending tags exist.

So, you can do something like this:

$content=eregi_replace(&quot;\\[url\\]www.([^\\[]*)\\[/url\\]&quot;,&quot;<a href=\&quot; target=_blank>\\1</a>&quot;,$content);
$content=eregi_replace(&quot;\\[url\\]([^\\[]*)\\[/url\\]&quot;,&quot;<a href=\&quot;\\1\&quot; target=_blank>\\1</a>&quot;,$content);


Chad. ICQ: 54380631
online.dll
 
just ask them to put in a url, u can check the validity with ereg:
eregi(&quot;([0-9a-z]([-\\.]?[0-9a-z])*\\.)+[a-z]{2,}:)[0-9]+)?(/[-/.=_&0-9a-z]*)?(\\?[-.=_&0-9a-z]*)?$&quot;, $site)

the u can put it in a [link bladiebla=yadda] [/url]

else u need to use substr($link((strlen($link) - 1), 1)
which means: take a sub section of a string starting form the last character with a length of one character.
This way u know if the last char is ']'
mcvdmvs
-- &quot;It never hurts to help&quot; -- Eek the Cat
 
What happens, though, if the user is writing a document and they have the following:

......
and then you can do $fp = fopen(&quot;
But, to see an example, go to ......

The user might not want to actually be converted to an active link since it is just an example url, whereas he DOES want the other one active because he wants the user to go to that location.

This is exactly why many forums use special formatting codes (like Tek-Tips) -- it allows for users to specify exactly what gets converted and formatted.

I think this is something that Tek-Tips should look at as well.

Chad.
[ignore][/ignore]
hmmmm....interesting.
ICQ: 54380631
online.dll
 
Ok i made it work:

function forum_opt($messege){
$messege = htmlspecialchars($messege);
while(TRUE){
$link = strpos($messege , &quot;[link=&quot;);
$link2 = strstr($messege,&quot;[link=&quot;);
$link3 = strpos($link2 , &quot;]&quot;);
$link4 = $link3+1 ;
$link5 = substr($link2, 0, $link4);
if(eregi('^\[link\=.*\]$' , $link5)){
$link5 = str_replace(&quot;[link=&quot; , &quot;<a href='&quot; , &quot;$link5&quot; );
$link5 = str_replace(&quot;]&quot; , &quot;'>&quot; , &quot;$link5&quot; );
$messege = substr_replace($messege , $link5 , $link , $link4);}
else
break;
}

it continuously checks the message and converts [link=http://www.mysite.com]link text[/url] until it cant find anymore and it breaks the loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top