Hide/shorten a long url in php

Discussion in 'PHP' started by srobona, Jul 18, 2007.

  1. #1
    Hi,

    need a solution to do this:

    suppose there is a url more than 40 chars long, like:

    fakekedomain.com/index.php?a=abd&b=bcd&page=5&set=12&name=url

    I want to make it like this: fakedomain.com/index.php?...name=url
    or, can i completely hide it from showing in the status bar?

    how can i do it? waiting for suitable suggestion :)
     
    srobona, Jul 18, 2007 IP
    nabil_kadimi likes this.
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    Well, I suppose check length of string if it is more than 20 chars for example, then use
     substr 
    PHP:
    to cut first 10 and last 10 chars from it.
     
    AsHinE, Jul 18, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    <a href="your-long-url-etc-etc-etc-etc" onmouseover="window.status=this.href.substring(0,10);" onmouseout="window.status='';">Link text</a>
    Code (markup):
    This only truncates (to 10 characters in this case), you can work with the this.href value to get a nicer value.

    I don't recommend doing this though, besides seeming like a waste of time and effort, browsers have options to disable sites from working with the status bar, some even by default, such as Firefox.
     
    krt, Jul 18, 2007 IP
  4. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #4
    oh, thanks for the help.
     
    srobona, Jul 18, 2007 IP
  5. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #5
    I think you are confused. Php is a server side language and can not message with a browsers status bar. I suggest you look into a javascript solution to hiding the link from the status bar mouseover.

    if you want to shorten what is shown in <a href="">THiS PORTION</a> then that is different.

    
    <?php
    function sniphref($href)
    {
      if(strlen($href) >= 20)
     {
        $starthref = substr($href,0,10);
        $endhref = substr($href,0,-10);
        $href = $starthref."...".$endhref;
     }
     else { }
      return $href;
    }
    
    echo "<a href='http://forums.digitalpoint.com/showthread.php?t=404468'>".sniphref("'http://forums.digitalpoint.com/showthread.php?t=404468")."</a>";
    
    ?>
    
    PHP:
    The above code has not been tested, but I think it works.
     
    exodus, Jul 18, 2007 IP
  6. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #6
    However, i'll try this code, and of course, thanks a lot for your kind help. :)
     
    srobona, Jul 19, 2007 IP
  7. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #7
    I redid it just a bit. Not much just the lengths are different.

    
    <?php
    function sniphref($href)
    {
    
      if(strlen($href) >= 30)
     {
        $starthref = substr($href,0,15);
        $endhref = substr($href,0,-10);
        $href = $starthref."...".$endhref;
     }
     else { }
      return $href;
    }
    
    echo "<a href='http://forums.digitalpoint.com/showthread.php?t=404468'>".sniphref("'http://forums.digitalpoint.com/showthread.php?t=404468")."</a>";
    
    ?>
    PHP:
    Output

    http://forums.digi...p?t=404468

    I don't know, play with it a bit to get the desired length to show.
     
    exodus, Jul 19, 2007 IP
    srobona and hasbehas like this.
  8. srobona

    srobona Active Member

    Messages:
    577
    Likes Received:
    57
    Best Answers:
    0
    Trophy Points:
    88
    #8
    Fantastic job! i was looking for exactly this type of work. Thanks a lot friend :p
     
    srobona, Jul 19, 2007 IP
  9. hasbehas

    hasbehas Well-Known Member

    Messages:
    726
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    190
    #9
    me too.. Thanks guys..
     
    hasbehas, Jul 21, 2007 IP
  10. exodus

    exodus Well-Known Member

    Messages:
    1,900
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    165
    #10
    I know it sounds redundant but I guess you can redo the function in this way too.

    function sniphref($href)
    {
    
      if(strlen($href) >= 30)
     {
        $href= substr($href,0,15)."...".substr($href,0,-10);
     }
    
      return $href;
    }
    PHP:
     
    exodus, Jul 21, 2007 IP