Posted link converts to title of the link

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Posted link converts to title of the link

    I have searched at g0ogle about this matter but i was not able to see the exact code i need. I want a script that everytime i post a link to a forum or shout box it views out the title of the link that enclosed by <title> and </title> an example is when i post http://php.net

    the output will be the title of the url page of http://php.net


    and the code will be <a href="http://php.net">Title of page here</a>

    instead of <a href="http://php.net">http://php.net</a>

    . Get my point? Can anyone give me a code?
    Last edited by analyzer; 14.04.12, 01:22.
    It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

    #2
    same topic came up not to long ago and someone answered it in there

    Comment


      #3
      Originally posted by something else View Post
      same topic came up not to long ago and someone answered it in there
      You'are About to Extract? title of Posted Link Just like fb do?
      Ya u Can Do Use file_get_contents
      nd use regxp to extract title
      Code:
      function page_title($url) {     $page = @file_get_contents($url);
      if (empty($page)) return null;    $matches = array();
      if (preg_match('/<title>(.*?)<\/title>/', $page, $matches))
      { 
      return $matches[1];
      }
      else
      {
      return null;
      }
      }
      usage
      Code:
      echo page_title("http://coding-talk.com/forum.php");
      Last edited by shushant; 14.04.12, 06:35.

      Comment


        #4
        What if i post "please visit http://www.example.com?"

        how it will be? I did not post a pure link. I can detect a url using a php script but my problem is how can i make the link clickable, you've just give me a code that detects the title. Can you give to me the continuation of the code that detects a url from a user post and make it clickable.
        It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

        Comment


          #5
          Search for auto url bb code its another topic that comes up quite a bit

          Comment


            #6
            Originally posted by analyzer View Post
            What if i post "please visit http://www.example.com?"

            how it will be? I did not post a pure link. I can detect a url using a php script but my problem is how can i make the link clickable, you've just give me a code that detects the title. Can you give to me the continuation of the code that detects a url from a user post and make it clickable.
            php - Turn a twitter hash tag into a link and links to clickable links - Stack Overflow

            Comment


              #7
              Originally posted by analyzer View Post
              What if i post "please visit http://www.example.com?"

              how it will be? I did not post a pure link. I can detect a url using a php script but my problem is how can i make the link clickable, you've just give me a code that detects the title. Can you give to me the continuation of the code that detects a url from a user post and make it clickable.
              PHP Code:
              <?php
              function page_title($url) {     

              if(
              preg_match('/http:\/\/www\./',$url)){ $ucc=preg_replace("/(.*?)www\./is","http://",$url); $linked=$ucc;}
              else if (
              preg_match('/^www\./',$url)){$linked=$url;}
              else { 
              $linked=$url;}

              $page = @file_get_contents($linked);
              if (!
              $page) {$null="Website does not exist !"; return $null; }   


              $matches = array();

              if (
              preg_match('/<title>(.*?)<\/title>/'$page$matches))

              return 
              $matches[1];
              }

              else
              {
              $null="Website does not exist !";
              return 
              $null;
              }
              }


              function 
              clicklinks($text)
              {       
              $regx1='/(((f|ht){1}tp:\/\/)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/';
              $regx2='/((^www.)[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/';
              $regx3='/([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&\/\/=]+)/';

              if (
              preg_match($regx1,$text,$title)){$linktitle page_title($title[0]);}
              else if (
              preg_match($regx2,$text,$title)){$linktitle page_title($title[0]);}
              else {if(
              preg_match($regx3,$text,$title)){$linktitle page_title($title[0]);}}
                  
              $text preg_replace($regx1.'i''<a href="\\1">'.$linktitle.'</a>',$text); 
              $text preg_replace($regx2.'i''<a href="http://\\1">'.$linktitle.'</a>',$text);     
              $text preg_replace($regx3.'i''\\1<a href="http://\\2">'.$linktitle.'</a>',$text);
              return 
              $text;
              }


              echo 
              clicklinks("there it has title from http://www.gowap.ro ");

              ?>

              There you go :p


              accepts

              Code:
              http:// , http://www. , www. ,ftp://
              hit tnx :D
              Last edited by just_m3.; 14.04.12, 15:36.
              This is ten percent luck, twenty percent skill
              Fifteen percent concentrated power of will
              Five percent pleasure, fifty percent pain

              And a hundred percent reason to remember the name!

              Comment


                #8
                looks like all the old auto url bb codes have been deleted
                so here is 1:
                PHP Code:
                $in=array('`((?:https?|ftp)://\S+[[:alnum:]]/?)`si',
                                  
                '`((?<!//)(www\.\S+[[:alnum:]]/?))`si');
                                  
                $out=array('<a href="?go=out&amp;site=$1">$1</a> ',
                                  
                '<a href="?go=out&amp;site=http://$1">$1</a>');
                                  
                $text preg_replace($in,$out,$text); 
                you will need to make it do separate preg replaces to use the get title code above though as it wont work in an array :P

                Added after 2 minutes:

                just_m3 posted few secs before i did so i didnt see his post
                Last edited by something else; 14.04.12, 14:42.

                Comment


                  #9
                  hmm
                  PHP Code:
                  echo clicklinks("there is no more link title like http://gowap.ro "); 
                  got to modd it x_X as it not gets title when combined with text ...

                  The script was updated :D ... check it ! now it works .. ;;) .. it is a little messy .. but it does the job !
                  Last edited by just_m3.; 14.04.12, 15:39. Reason: modding ... update
                  This is ten percent luck, twenty percent skill
                  Fifteen percent concentrated power of will
                  Five percent pleasure, fifty percent pain

                  And a hundred percent reason to remember the name!

                  Comment


                    #10
                    Thanky0u guys! It helps me a lot. . Sorry but i can't click the "thanks" button at this moment. . I am just using a phone to browse cd. But don't you worry, i will hit thanks later when i use my pc. . Thankyou again.
                    It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

                    Comment


                      #11
                      @just_m3 i tried the code bro and it works. But there's a problem, i tried to put 2 different links but the title was the same. How will i'm going to fix the problem bro?
                      It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

                      Comment


                        #12
                        Originally posted by analyzer View Post
                        @just_m3 i tried the code bro and it works. But there's a problem, i tried to put 2 different links but the title was the same. How will i'm going to fix the problem bro?
                        Hmmm let me check it out :D ... he might require for each .. i've got an idea . tnx for posting this issue :p
                        This is ten percent luck, twenty percent skill
                        Fifteen percent concentrated power of will
                        Five percent pleasure, fifty percent pain

                        And a hundred percent reason to remember the name!

                        Comment


                          #13
                          Ok bro. . Please post it here if ever you solve the problem. . I think while loop can solve that. .
                          Last edited by analyzer; 16.04.12, 05:18.
                          It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

                          Comment


                            #14
                            Just use preg_match_all() instead.
                            <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                            Comment


                              #15
                              @arnage where to put that preg_match_all() mate?
                              It's n0t that i am afraid to die. Its just that if i die, wh0 wilL loVe her as muCh as i Do?

                              Comment

                              Working...
                              X