SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function format_link problem

    hey guys. I got this function off of phpbuilder.com. IT supposed to take an unformatted plain text variable (submitted via form) and parse it making plaintext links actual html links. Unfortunately, it's not working. Link Format failed. Here's the function followed by the method I'm calling it.
    PHP Code:
    <?php
    function format_links($chk_str){
      
    $a explode(" "$chk_str);
      for(
    $i=0$i<count($a); $i++){
      
    $b str_replace("www.""http://www."$a[$i]);
      
    $b str_replace("http://http://""http://"$b);
      
    $pos strpos($b"http://");
      if (
    $pos === false) { //note: three equal signs
      
    $url_found false;
      } else {
      
    $url_found true;
      }
      if(
    $url_found){
      
    $a[$i] = "<a href='$b' target=_blank>$b</a>";
      }
      
    $pos strpos($b"@");
      if(
    $pos === false){
      
    $email false;
      } else {
      
    $email true;
      }
      if(
    $email){
      
    $a[$i] = "<a href='mailto:$b'>$b</a>";
      }
      }
      
    $chk_str implode(" "$a);
      return 
    $chk_str;
    }
    ?>
    Here's the call (should $message be $chk_str?):
    PHP Code:
    <?php
    $message 
    "Blah! www.livingpages.net";
    $HTMLmessage = @format_links($message); {
    if(!
    $HTMLmessage); {
    exit(
    "<p>Link Format failed</p>");
    }
    }
    ?>
    Last edited by Sketch; Jan 5, 2002 at 01:39.
    Aaron Brazell
    Technosailor



  2. #2
    SitePoint Enthusiast UCAP's Avatar
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try something like this:

    PHP Code:
    <?php
    $message 
    "Blah! www.livingpages.net";
    $HTMLmessage = @format_links($message);
    if(!
    $HTMLmessage) echo ("<p>Link Format failed</p>");
    else echo 
    $HTMLmessage;
    ?>

  3. #3
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sketch, the variable name where you're calling it doesn't matter. however, on the line where you call the function, you have a "{" at the end -- that shouldn't be there.

    but, i have to say, that is some of the *WORST*/ineffecient, sloppy code i've ever seen! here, if you want something that works good (very good at finding actual links) and is fast, look at my code here: http://www.sitepointforums.com/showt...784#post320784

    usage:

    $message = make_clickable($message);
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  4. #4
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll try these in a bit and get back to you. Larry, I know it was unoptimized but at 2:30 in the morning, I couldn't concentrate on php to write a corrcetly fashioned function, so I stole this one. LOL....I'll check back.

    Sketch
    Aaron Brazell
    Technosailor



  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Larry,

    your function worked great in poutting the message into HTML format but I can't figure out why it is not displayed in HTML format now. instead of this:www.livingpages.net, it is displayed like this:
    Code:
    <a href="http://www.livingpages.net" target="_blank">www.livingpages.net</a>
    ...still in plaintext.

    Sketch

    EDIT....change the mime type.
    Last edited by Sketch; Jan 5, 2002 at 18:39.
    Aaron Brazell
    Technosailor



  6. #6
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    question : how would you put line breaks in a $message that has been put through the make_clickable() wringer? In plaintext the \n's put the line breaks in, but after make_clickable() all line breaks are stripped.

    Sketch
    Aaron Brazell
    Technosailor



  7. #7
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nl2br(), just like usual. you can use it before or after make_clickable() -- doesn't matter.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •