[php] 자동 하이퍼 링크 생성

인자로 보낸 $comment 중에 html 주소가 있을 경우 하이퍼 링크를 생성해서 리턴합니

다.

<?

function url_comment($comment)

{

    global $urlcomment;

    $whitespace = ” “;

    $whitespace .= $comment;

    $comment = $whitespace;

    $i = -1;

    $urlpresent = “”;

    $urlcheck  = “”;

    $comment .= ” “;

    $comment = ereg_replace(“<br>”,””,$comment);

    $comlength = strlen(“$comment”);

    $urlpresent = ereg_replace(”

http://”,”urlisfoundheremofo”,$comment);

    

    if ($urlpresent != $comment)

    {

        $urlhere = 1;

    }

    if ($urlhere == 1)

    {

        $subcomment = $comment;

        while ($urlcheck != “complete”)

        {

            $toadd = 0;

            ++$i;

            $startoflink[$i] = strpos($subcomment,” http://”);

            ++$startoflink[$i];

            $spacecheck[$i] = $startoflink[$i];

            $nextcheck = $spacecheck[$i] + 7;

            $subcomlength = strlen(“$subcomment”);

            $toadd = $comlength – $subcomlength;

            $spacecheck[$i] = $spacecheck[$i] + $toadd;

            $newcomlength = $comlength – $nextcheck;

            $subcomment = substr($subcomment,$nextcheck, $newcomlength);

            $urlpresent2 = ereg_replace

(“http://”,”urlisfoundheremofo”,$subcomment);

            

            if ($urlpresent2 == $subcomment)

            {

                $urlcheck = “complete”;

            }

        }

        $x = 0;

        $maxi = $i;

        while ($i > -1)

        {

            $checker = “”;

            while ($checker != ” ” and $checker != “\\n”)

            {

                $checker = substr($comment, $spacecheck[$i], 1);

    

                if ($checker != ” ” and $checker != “\\n”)

                {

                    $string[$i] .= $checker;

                }

                ++$spacecheck[$i];

            }

            –$i;

        }

        $i = $maxi;

        while ($i > -1)

        {

            while(!ereg(“^.*([[:alnum:]]|/)$”, $string[$i]))

            {

                $length = strlen(“$string[$i]”);

                $toget = $length – 1;

                $string[$i] = substr($string[$i], 0, $toget);

            }

            –$i;

        }

        sort($string);

        $i = $maxi;

        while ($i > -1)

        {

            $comment = ereg_replace(” $string[$i]”,” <a

href=$string[$i]>$string[$i]

</a>”,$comment);

            –$i;

        }

        $comment = ereg_replace(“\\n”,”<br>”,$comment);

    }

    $comment = ereg_replace(“\\n”,”<br>”,$comment);

    $urlcomment = $comment;

}

?>

서진우

슈퍼컴퓨팅 전문 기업 클루닉스/ 상무(기술이사)/ 정보시스템감리사/ 시스존 블로그 운영자

You may also like...

페이스북/트위트/구글 계정으로 댓글 가능합니다.