Link Convertor

This is guide mostly for website tools and code, for example CMS or registration scripts.
There can also be tools.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

Link Convertor

Postby Rifke on Thu Aug 09, 2007 3:20 pm

Link Convertor

Like the title explains a Link Convertor, but what is a link convertor. Well it changes a link to a section link. Clickable / section.

It's quite hard to explain but it works as follows.
http:// www .example.com/index.php?page=home&subpage=About&mpage=5&reply=1547
(Cutted due the board coverts it in to a clickable link.)
The Link Convertor converts into:
Home > About > 5 > 1547

As you see it is not that perfect, to make it use meaning names instead of 5 & 1547, you'll have to come up with a own idea. I am still working on that one.

You could make your link like http:// www .example.com/index.php?page=home&subpage=About&mpage=MPage_5&reply=Reply_1547
It would convert in this
Home > About > MPage_5 > Reply_1547

  1. <?php
  2. function link_convertor($url,$skip=0)
  3. {
  4.     $r = explode('?',$url)
  5.     for ($s = 0; $s < count($s); $s++)
  6.     {
  7.         $a = explode('&',$r[$s]);
  8.         for ($x = 0; $x < count($a); $x++)
  9.         {
  10.             $b = explode('=',$a[$x]);
  11.             $sep[] = $b[0];
  12.             $tmp[] = $b[1];
  13.         }
  14.        
  15.         for ($i = 0; $i < count($sep); $i++)
  16.         {
  17.             ( $i == 0) ? $sr = '?' : $sr = '&';
  18.             $tmp[$i]= str_replace('%20',' ',$tmp[$i]);
  19.                 $linkchr = strlen($tmp[$i]);
  20.                 if ( $linkchr > 15 ) {
  21.                     $msg = substr($tmp[$i],0,4);
  22.                     $msg .= '...';
  23.                     $msg .= substr($tmp[$i],$linkchr-5,$linkchr);
  24.                 } else {
  25.                     $msg = ucfirst($tmp[$i]);
  26.                 }
  27.                
  28.             if ($i == count($sep)-1)
  29.             {
  30.                 if ( $tmp[$i] == NULL ) {}
  31.                 else {
  32.                     $o .= ' &raquo; '.ucfirst($tmp[$i]);
  33.                 }
  34.             }
  35.             else
  36.             {
  37.                 $link = $link.$sr.$sep[$i].'='.$tmp[$i];
  38.                 if ( $i < $skip ) { }
  39.                 else {
  40.                     $o .= ( $i == 0 ) ? ' ' : ' &raquo; ';
  41.                     $o .= '<a href="'.$link.'" >'.$msg.'</a>';
  42.                 }
  43.             }
  44.            
  45.            
  46.         }
  47.     }
  48. //  return '<a href="?'.$r[0].'='.$r[0].'" >edede</a>'.$o;
  49.     return $o;
  50. }
  51. ?>


example:
  1. $Link = link_convertor($_SERVER['QUERY_STRING']);
  2. echo $Link;
Last edited by lmame on Thu Aug 09, 2007 6:57 pm, edited 1 time in total.
Reason: Lmame: Title changed.
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium

Re: Link Creator

Postby Drkpanoz on Thu Aug 09, 2007 6:44 pm

Actually, the title reads 'Link Creator' :mrgreen:
Drkpanoz
Jelly Bean
Jelly Bean
 
Posts: 11
Joined: Thu Aug 09, 2007 6:38 pm

Re: Link Convertor

Postby lmame on Thu Aug 09, 2007 6:57 pm

I changed the title :)
The world is full of love and peace ^_^
Image
User avatar
lmame
Admin
Admin
 
Posts: 8997
Joined: Mon Aug 06, 2007 4:42 pm
Location: July City

Re: Link Convertor

Postby Drkpanoz on Thu Aug 09, 2007 6:59 pm

lmame wrote:I changed the title :)

Ah, that's better :D
Drkpanoz
Jelly Bean
Jelly Bean
 
Posts: 11
Joined: Thu Aug 09, 2007 6:38 pm

Re: Link Convertor

Postby Rifke on Thu Aug 09, 2007 7:46 pm

Oh well :D it does the same still. Convertor or Creator. I don't think the difference is huge between the two words.
Rifke
Pero pero
Pero pero
 
Posts: 719
Joined: Thu Aug 09, 2007 3:01 pm
Location: Belgium


Return to PHP / Web Guides, Scripts and tools.

Who is online

Users browsing this forum: No registered users and 8 guests

cron