Php chat, allow simple html tags

I need some help with my chat script which does not allow html codes. I need it to allow and tags so users could edit their texts a bit. I have been battling with this problem for some time now and finally decided to ask help from here.

My system turns urls to links, so there is some kind of base system for some html, but i need those text editing systems.

This is part of my code which allows some specified html tags, there is also the part where i need my bold, italic and underline codes to:

[code]// Convert message body into HTML string
// @param string body Message body
// @return string
function parseMessage(body) {
var parsed=’’;
var msg_parts=null;
var found=false;
var pos=0;
var tmp=’’;
var converted_parts=new Array();

if (typeof(body)==‘string’ && body!=’’) {
msg_parts=body.split(’ ');

// B I U codes

/**

  • HERE I WANT THEM
    */

    // Convert URLs
    for (var i=0; i<msg_parts.length; i++) {
    if (msg_parts[i]!=’ ‘) {
    tmp=msg_parts[i].toLowerCase();
    if (tmp.indexOf(’:’)>0) {
    tmp=tmp.split(’:’, 2);
    if (tmp.length==2 && tmp[1]!=’’) {
    switch (tmp[0]) {

           // URI://...
           case 'acap' :
           case 'cap' :
           case 'crid' :
           case 'dict' :
           case 'dns' :
           case 'ed2k' :
           case 'file' :
           case 'ftp' :
           case 'gopher' :
           case 'http' :
           case 'https' :
           case 'irc' :
           case 'ircs' :
           case 'lastfm' :
           case 'mms' :
           case 'nntp' :
           case 'rsync' :
           case 'sftp' :
           case 'smb' :
           case 'snmp' :
           case 'ssh' :
           case 'telnet' :
             if (tmp[1].length>2 && 0==tmp[1].indexOf('//')) {
               // OK
               msg_parts[i]='<a target="_blank" href="'+formlink+'?external_url='+urlencode(msg_parts[i])+'" title="'+msg_parts[i]+'">'+htmlspecialchars(msg_parts[i])+'</a>';
               converted_parts[i]=1;
             }
           break;
    
           // URI://...
           case 'aaa' :
           case 'aaas' :
           case 'about' :
           case 'aim' :
           case 'callto' :
           case 'cid' :
           case 'data' :
           case 'dav' :
           case 'fax' :
           case 'feed' :
           case 'go' :
           case 'imap' :
           case 'imaps' :
           case 'ldap' :
           case 'mailto' :
           case 'mailto' :
           case 'mid' :
           case 'msnim' :
           case 'news' :
           case 'nfs' :
           case 'pop' :
           case 'pop3' :
           case 'pops' :
           case 'pop3s' :
           case 'pres' :
           case 'sip' :
           case 'sips' :
           case 'skype' :
           case 'tel' :
           case 'urn' :
           case 'wais' :
           case 'xmpp' :
           case 'ymsgr' :
             if (tmp[1].length>1) {
               // OK
               msg_parts[i]='<a target="_blank" href="'+formlink+'?external_url='+urlencode(msg_parts[i])+'" title="'+htmlspecialchars(msg_parts[i])+'">'+htmlspecialchars(msg_parts[i])+'</a>';
               converted_parts[i]=1;
             }
           break;
    
         }
       }
     }
     if (typeof(converted_parts[i])=='undefined' && 0==msg_parts[i].indexOf('www.') && msg_parts[i].length>=9) {
       // HTTP link begins with "www."
       msg_parts[i]='<a target="_blank" href="'+formlink+'?external_url='+urlencode('http://'+msg_parts[i])+'" title="'+htmlspecialchars(msg_parts[i])+'">'+htmlspecialchars(msg_parts[i])+'</a>';
       converted_parts[i]=1;
     }
    

    }
    }

    // Convert smilies
    for (var i=0; i<msg_parts.length; i++) {
    if (typeof(converted_parts[i])==‘undefined’) {
    found=false;
    if (msg_parts[i]!=’’) {
    for (var code in SmilieList.SmilieList) {
    if (msg_parts[i]==code) {
    msg_parts[i]=’'+code+'’;
    found=true;
    break;
    }
    }
    if (found==false) {
    msg_parts[i]=htmlspecialchars(msg_parts[i]);
    }
    }
    }

    body=msg_parts.join(’ ');
    }
    parsed=body;
    }
    return parsed;
    }[/code]

Sponsor our Newsletter | Privacy Policy | Terms of Service