phpwikiwiki-engine

Make Automatic Links in a Text from File : Like Internal Wikipedia - PHP


I want help on this script I am making...

I want my website to be a wikipedia in itself... take for example I have a php website... I publish daily articles on it.

Suppose I publish 2 articles on Jenna Bush and Michael Jackson respectively

now I save into text/xml/database text and link

example

jenna bush, http://www.domain.com/jenna.html    
michael jackson, http://www.domain.com/michael.html

or any which ways required like

<xml>
<item>
<text>jenna bush</text>
<link>http://www.domain.com/jenna.html</link>
</item>
... etc
</xml>

now what I want is the PHP script should automatically convert any jenna bush or any michael jackson linked to their respective links all over my website...

Any help is much appreciated...


Solution

  • I customized it and here is for everyone interested

    function tags_autolink($text) 
    {
    
    $text = " $text ";
    $query_tags_autolink = "SELECT tag from tags";
    $rs_tags_autolink = mysql_query($query_tags_autolink) or print "error getting tags";
    
    while($row_tags_autolink = mysql_fetch_array($rs_tags_autolink))
    {
    $tag_name = trim($row_tags_autolink['tag']);
    $tag_url = "http://www.domain.com/tag/".createLink(trim(htmlentities($tag_name)))."/";
    $text = preg_replace("|(?!<[^<>]*?)(?<![?./&])\b($tag_name)\b(?!:)(?![^<>]*?>)|imsU","<a href=\"$tag_url\">$1</a>" , $text);
    }
    
    return trim( $text );
    }
    

    the create link function simply makes a string of "abcd is kk" like "abcd-is-kk" for a tag page ending ;)

    cheers !