Welcome Guest, Not a member yet? Register   Sign In
Help with parse_smileys and HTML entities
#4

[eluser]sophistry[/eluser]
here's a hack the core way to do it, and just may fit your requirements:
EDIT: bah! ::bug:: the forum messed up the PHP code, but the important parts are still showing.

the smiley helper is just a silly old str_replace()

Code:
// ------------------------------------------------------------------------

/**
* Parse Smileys
*
* Takes a string as input and swaps any contained smileys for the actual image
*
* @access    public
* @param    string    the text to be parsed
* @param    string    the URL to the folder containing the smiley images
* @return    string
*/    
if ( ! function_exists('parse_smileys'))
{
    function parse_smileys($str = '', $image_url = '', $smileys = NULL)
    {
        if ($image_url == '')
        {
            return $str;
        }

        if ( ! is_array($smileys))
        {
            if (FALSE === ($smileys = _get_smiley_array()))
            {
                return $str;
            }        
        }
    
        // Add a trailing slash to the file path if needed
        $image_url = preg_replace("/(.+?)\/*$/", "\\1/",  $image_url);

        foreach ($smileys as $key => $val)
        {        
            $str = str_replace($key, "<img  />", $str);
        }
    
        return $str;
    }
}

if you require that smileys be proceeded by a space character, then str_replace() will only find those and not the entities.
so, just put a space char in front of $key in the foreach loop:

Code:
// added spsce char to first param of str_replace()
$str = str_replace(' '.$key, "<img  />", $str);

now that i am looking at this, it does seem that smiley helper should know this already! is it a bug?


Messages In This Thread
Help with parse_smileys and HTML entities - by El Forum - 09-29-2008, 07:37 PM
Help with parse_smileys and HTML entities - by El Forum - 09-29-2008, 09:55 PM
Help with parse_smileys and HTML entities - by El Forum - 09-30-2008, 07:43 AM
Help with parse_smileys and HTML entities - by El Forum - 09-30-2008, 08:40 AM
Help with parse_smileys and HTML entities - by El Forum - 09-30-2008, 08:57 AM
Help with parse_smileys and HTML entities - by El Forum - 09-30-2008, 09:19 AM
Help with parse_smileys and HTML entities - by El Forum - 09-30-2008, 09:41 AM
Help with parse_smileys and HTML entities - by El Forum - 09-30-2008, 10:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB