NameSilo

BBCODE help

SpaceshipSpaceship
Watch

bio2pets

Established Member
Impact
2
if anyone could help please. im having trouble.

im trying to insert bbcode for image to allow my users to be able to add images to thier profile.

i tryed doing it by adding this code:

'%\\[img\\]([^\\[]*)\\[/img\\]%',

and also this code:

'<img src=\"\\1\"> ',

i am still getting a broken image please help.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable Domains โ€” AI StorefrontUnstoppable Domains โ€” AI Storefront
try:

PHP:
$image_code = eregi_replace('(\[img\]|\[/img\])','',$img);

Not sure if it would work though
 
0
•••
Mikor, that would replace their code with nothing.

Try this:
PHP:
$string = preg_replace('/\[img\](.*?)\[\/img\]/i', '<img src="$1">', $string);
 
0
•••
i need the code in this format if possible


PHP:
<?php
	/* Check Structure Availability */
	if (!defined("CORE_STRAP")) die("Out of structure call");


	/*
		Those are the body codes conversion functions.
		They are used wherever a user-submitted body is
		parsed. The first function convert the body 
		codes to HTML entities, the second one remove
		those body codes.
	*/
	
	
	function convertBodyCodes($body) {
		
		/*
			The following is the replacement array, note
			that the spaces before and after HTML versions
			is used to prevent building up long strings that
			can't be cut by the chopper function bewlow as
			it was built not to cut in the middle of a string
			that stands inside a html tag - this prevents
			cutting a long link in two parts thus making it
			unusable
		*/
		$BCRegExpArrayPattern = array(
			'/(!|!){10,}/',
			'%\\[color (([a-zA-Z0-9#]*))\\]([^\\[]*)\\[/color\\]%',
			'%\\[b\\]([^\\[]*)\\[/b\\]%',
			'%\\[img\\]([^\\[]*)\\[/img\\]%',
			'%\\[i\\]([^\\[]*)\\[/i\\]%',
			'%\\[u\\]([^\\[]*)\\[/u\\]%',
			'%\\[quote\\]([^\\[]*)\\[/quote\\]%',
			'%\\[s\\]([^\\[]*)\\[/s\\]%',
			'%\\[tt\\]([^\\[]*)\\[/tt\\]%',
			'/\\b((https?|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\\?[-A-Z0-9+&@#\/%=~_|!:,.;]*)?)/si',
			'/\\n/',
		);
		
		$BCRegExpArrayReplace = array(
			'!',
			'<span style="color: \\1">\\3</span> ',
			'<strong>\\1</strong> ',
			'<img src=\"\\1\"> ',
			'<em>\\1</em> ',
			'<u>\\1</u> ',
			'<blockquote><p> \\1 </p></blockquote>',
			'<s>\\1</s> ',
			'<tt>\\1</tt> ',
			'<a href="\\1" target="_blank">\\3</a>',
			'<br /> ',
		);

		$body = preg_replace($BCRegExpArrayPattern, $BCRegExpArrayReplace, $body);

		foreach(explode(" ", strip_tags($body)) as $key => $line) {
			/*
				Break long strings into smaller chunks (prevents
				destroying the interface with a 500 characters
				long "word"
			*/
			if (strlen($line) > 50) $body = str_replace($line, wordwrap($line, 25, " ", 1), $body);
			
		}
		
		/* 
			Return the body to the caller
		*/
		return $body;
	}
	
	function clearBodyCodes($body) {

		/*
			The following is the replacement array. All the body
			codes are converted into a single space (except the
			\n character which is still converted into a BR)
		*/
		$BCRegExpArrayPattern = array(
			'/(!|!){10,}/',
			'%\\[color (([a-zA-Z0-9#]*))\\]([^\\[]*)\\[/color\\]%',
			'%\\[b\\]([^\\[]*)\\[/b\\]%',
			'%\\[img\\]([^\\[]*)\\[/img\\]%',
			'%\\[i\\]([^\\[]*)\\[/i\\]%',
			'%\\[u\\]([^\\[]*)\\[/u\\]%',
			'%\\[quote\\]([^\\[]*)\\[/quote\\]%',
			'%\\[s\\]([^\\[]*)\\[/s\\]%',
			'%\\[tt\\]([^\\[]*)\\[/tt\\]%',
			'/\\n/',
		);
		
		$BCRegExpArrayReplace = array(
			'!',
			'\\3 ',
			'\\1 ',
			'\\1 ',
			'\\1 ',
			'\\1 ',
			'\\1 ',
			'\\1 ',
			'<br /> ',
		);
		 
		$body = preg_replace($BCRegExpArrayPattern, $BCRegExpArrayReplace, $body);

		/*
			Break long strings into smaller chunks (prevents
			destroying the interface with a 500 characters
			long "word"
		*/
		foreach(explode(" ", strip_tags($body)) as $key => $line) {
			if (strlen($line) > 50) $body = str_replace($line, wordwrap($line, 25, " ", 1), $body);
		}
		
		/* 
			Return the body to the caller
		*/
		return $body;
	}
	
	function convertImages($body) {
		return preg_replace(
			'%\\[image (([a-zA-Z0-9\\.:_\\/]*))\\]%im', 
			"<div style=\"clear:both;\">"
			."<a href=\"\\1\" target=\"_blank\">"
			."<img src=\"system/imagestream.php?location=\\1\" id=\"bodyCodeImage\">"
			."</a></div>", 
		$body);
	}
	
	function convertEmoticons($body) {
		
		$emoticons = array(
			":-(|)"    => "face-monkey.png",
			":devil:"  => "face-devil-grin.png",
			"0:)"      => "face-angel.png",
			":~("      => "face-crying.png",
			"B-)"      => "face-glasses.png",
			"B)"       => "face-glasses.png",
			":*"       => "face-kiss.png",
			":|"       => "face-plain.png",
			":("       => "face-sad.png",
			":)"       => "face-smile.png",
			":D"       => "face-smile-big.png",
			":O"       => "face-surprise.png",
			";)"  => "face-wink.png",
			";-)" => "face-wink.png",
			":idea:"   => "idea.png",
			":love:"   => "love.png",
			":music:"  => "music.png",
		);

		foreach ($emoticons as $emot => $image) {
			$body = str_replace($emot, "<img src=\"theme/{$GLOBALS["THEME"]}/images/icons/emoticons/{$image}\" align=\"absbottom\" width=\"16\" height=\"16\">", $body);
		}
		
		return $body;
	}

?>
 
0
•••
PHP:
<?php
    /* Check Structure Availability */
    if (!defined("CORE_STRAP")) die("Out of structure call");


    /*
        Those are the body codes conversion functions.
        They are used wherever a user-submitted body is
        parsed. The first function convert the body 
        codes to HTML entities, the second one remove
        those body codes.
    */
    
    
    function convertBodyCodes($body) {
        
        /*
            The following is the replacement array, note
            that the spaces before and after HTML versions
            is used to prevent building up long strings that
            can't be cut by the chopper function bewlow as
            it was built not to cut in the middle of a string
            that stands inside a html tag - this prevents
            cutting a long link in two parts thus making it
            unusable
        */
        $BCRegExpArrayPattern = array(
            '/(!|!){10,}/',
            '%\\[color (([a-zA-Z0-9#]*))\\]([^\\[]*)\\[/color\\]%',
            '%\\[b\\]([^\\[]*)\\[/b\\]%',
            '/\[img\](.*?)\[\/img\]/i',
            '%\\[i\\]([^\\[]*)\\[/i\\]%',
            '%\\[u\\]([^\\[]*)\\[/u\\]%',
            '%\\[quote\\]([^\\[]*)\\[/quote\\]%',
            '%\\[s\\]([^\\[]*)\\[/s\\]%',
            '%\\[tt\\]([^\\[]*)\\[/tt\\]%',
            '/\\b((https?|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\\?[-A-Z0-9+&@#\/%=~_|!:,.;]*)?)/si',
            '/\\n/',
        );
        
        $BCRegExpArrayReplace = array(
            '!',
            '<span style="color: \\1">\\3</span> ',
            '<strong>\\1</strong> ',
            '<img src="$1"> ',
            '<em>\\1</em> ',
            '<u>\\1</u> ',
            '<blockquote><p> \\1 </p></blockquote>',
            '<s>\\1</s> ',
            '<tt>\\1</tt> ',
            '<a href="\\1" target="_blank">\\3</a>',
            '<br /> ',
        );

        $body = preg_replace($BCRegExpArrayPattern, $BCRegExpArrayReplace, $body);

        foreach(explode(" ", strip_tags($body)) as $key => $line) {
            /*
                Break long strings into smaller chunks (prevents
                destroying the interface with a 500 characters
                long "word"
            */
            if (strlen($line) > 50) $body = str_replace($line, wordwrap($line, 25, " ", 1), $body);
            
        }
        
        /* 
            Return the body to the caller
        */
        return $body;
    }
    
    function clearBodyCodes($body) {

        /*
            The following is the replacement array. All the body
            codes are converted into a single space (except the
            \n character which is still converted into a BR)
        */
        $BCRegExpArrayPattern = array(
            '/(!|!){10,}/',
            '%\\[color (([a-zA-Z0-9#]*))\\]([^\\[]*)\\[/color\\]%',
            '%\\[b\\]([^\\[]*)\\[/b\\]%',
            '%\\[img\\]([^\\[]*)\\[/img\\]%',
            '%\\[i\\]([^\\[]*)\\[/i\\]%',
            '%\\[u\\]([^\\[]*)\\[/u\\]%',
            '%\\[quote\\]([^\\[]*)\\[/quote\\]%',
            '%\\[s\\]([^\\[]*)\\[/s\\]%',
            '%\\[tt\\]([^\\[]*)\\[/tt\\]%',
            '/\\n/',
        );
        
        $BCRegExpArrayReplace = array(
            '!',
            '\\3 ',
            '\\1 ',
            '\\1 ',
            '\\1 ',
            '\\1 ',
            '\\1 ',
            '\\1 ',
            '<br /> ',
        );
         
        $body = preg_replace($BCRegExpArrayPattern, $BCRegExpArrayReplace, $body);

        /*
            Break long strings into smaller chunks (prevents
            destroying the interface with a 500 characters
            long "word"
        */
        foreach(explode(" ", strip_tags($body)) as $key => $line) {
            if (strlen($line) > 50) $body = str_replace($line, wordwrap($line, 25, " ", 1), $body);
        }
        
        /* 
            Return the body to the caller
        */
        return $body;
    }
    
    function convertImages($body) {
        return preg_replace(
            '%\\[image (([a-zA-Z0-9\\.:_\\/]*))\\]%im', 
            "<div style=\"clear:both;\">"
            ."<a href=\"\\1\" target=\"_blank\">"
            ."<img src=\"system/imagestream.php?location=\\1\" id=\"bodyCodeImage\">"
            ."</a></div>", 
        $body);
    }
    
    function convertEmoticons($body) {
        
        $emoticons = array(
            ":-(|)"    => "face-monkey.png",
            ":devil:"  => "face-devil-grin.png",
            "0:)"      => "face-angel.png",
            ":~("      => "face-crying.png",
            "B-)"      => "face-glasses.png",
            "B)"       => "face-glasses.png",
            ":*"       => "face-kiss.png",
            ":|"       => "face-plain.png",
            ":("       => "face-sad.png",
            ":)"       => "face-smile.png",
            ":D"       => "face-smile-big.png",
            ":O"       => "face-surprise.png",
            ";)"  => "face-wink.png",
            ";-)" => "face-wink.png",
            ":idea:"   => "idea.png",
            ":love:"   => "love.png",
            ":music:"  => "music.png",
        );

        foreach ($emoticons as $emot => $image) {
            $body = str_replace($emot, "<img src=\"theme/{$GLOBALS["THEME"]}/images/icons/emoticons/{$image}\" align=\"absbottom\" width=\"16\" height=\"16\">", $body);
        }
        
        return $body;
    }

?>
 
0
•••
The image replacement works, but it's taking my image location and changing it to a link also, so that the HTML comes out like this:

HTML:
<img src="<a href="http://nightspot.ca/theme/default/images/icons/headers/myself.gif" target="_blank">nightspot.ca</a>">
 
Last edited:
0
•••
PHP:
  <?php
    /* Check Structure Availability */
    if (!defined("CORE_STRAP")) die("Out of structure call");


    /*
        Those are the body codes conversion functions.
        They are used wherever a user-submitted body is
        parsed. The first function convert the body 
        codes to HTML entities, the second one remove
        those body codes.
    */
    
    
    function convertBodyCodes($body) {
        
        /*
            The following is the replacement array, note
            that the spaces before and after HTML versions
            is used to prevent building up long strings that
            can't be cut by the chopper function bewlow as
            it was built not to cut in the middle of a string
            that stands inside a html tag - this prevents
            cutting a long link in two parts thus making it
            unusable
        */
        $BCRegExpArrayPattern = array(
            '/(!|!){10,}/',
            '%\\[color (([a-zA-Z0-9#]*))\\]([^\\[]*)\\[/color\\]%',
            '%\\[b\\]([^\\[]*)\\[/b\\]%',
            '/\[img\](.*?)\[\/img\]/i',
            '%\\[i\\]([^\\[]*)\\[/i\\]%',
            '%\\[u\\]([^\\[]*)\\[/u\\]%',
            '%\\[quote\\]([^\\[]*)\\[/quote\\]%',
            '%\\[s\\]([^\\[]*)\\[/s\\]%',
            '%\\[tt\\]([^\\[]*)\\[/tt\\]%',
            '/\\b((https?|ftp):\/\/([-A-Z0-9.]+)(\/[-A-Z0-9+&@#\/%=~_|!:,.;]*)?(\\?[-A-Z0-9+&@#\/%=~_|!:,.;]*)?)/si',
            '/\\n/',
        );
        
        $BCRegExpArrayReplace = array(
            '!',
            '<span style="color: \\1">\\3</span> ',
            '<strong>\\1</strong> ',
            '<img src="$1"> ',
            '<em>\\1</em> ',
            '<u>\\1</u> ',
            '<blockquote><p> \\1 </p></blockquote>',
            '<s>\\1</s> ',
            '<tt>\\1</tt> ',
            '<a href="\\1" target="_blank">\\3</a>',
            '<br /> ',
        );

        $body = preg_replace($BCRegExpArrayPattern, $BCRegExpArrayReplace, $body);

        foreach(explode(" ", strip_tags($body)) as $key => $line) {
            /*
                Break long strings into smaller chunks (prevents
                destroying the interface with a 500 characters
                long "word"
            */
            if (strlen($line) > 50) $body = str_replace($line, wordwrap($line, 25, " ", 1), $body);
            
        }
        
        /* 
            Return the body to the caller
        */
        return $body;
    }
    
    function clearBodyCodes($body) {

        /*
            The following is the replacement array. All the body
            codes are converted into a single space (except the
            \n character which is still converted into a BR)
        */
        $BCRegExpArrayPattern = array(
            '/(!|!){10,}/',
            '%\\[color (([a-zA-Z0-9#]*))\\]([^\\[]*)\\[/color\\]%',
            '%\\[b\\]([^\\[]*)\\[/b\\]%',
            '%\\[img\\]([^\\[]*)\\[/img\\]%',
            '%\\[i\\]([^\\[]*)\\[/i\\]%',
            '%\\[u\\]([^\\[]*)\\[/u\\]%',
            '%\\[quote\\]([^\\[]*)\\[/quote\\]%',
            '%\\[s\\]([^\\[]*)\\[/s\\]%',
            '%\\[tt\\]([^\\[]*)\\[/tt\\]%',
            '/\\n/',
        );
        
        $BCRegExpArrayReplace = array(
            '!',
            '\\3 ',
            '\\1 ',
            '\\1 ',
            '\\1 ',
            '\\1 ',
            '\\1 ',
            '\\1 ',
            '<br /> ',
        );
         
        $body = preg_replace($BCRegExpArrayPattern, $BCRegExpArrayReplace, $body);

        /*
            Break long strings into smaller chunks (prevents
            destroying the interface with a 500 characters
            long "word"
        */
        foreach(explode(" ", strip_tags($body)) as $key => $line) {
            if (strlen($line) > 50) $body = str_replace($line, wordwrap($line, 25, " ", 1), $body);
        }
        
        /* 
            Return the body to the caller
        */
        return $body;
    }
    
    function convertEmoticons($body) {
        
        $emoticons = array(
            ":-(|)"    => "face-monkey.png",
            ":devil:"  => "face-devil-grin.png",
            "0:)"      => "face-angel.png",
            ":~("      => "face-crying.png",
            "B-)"      => "face-glasses.png",
            "B)"       => "face-glasses.png",
            ":*"       => "face-kiss.png",
            ":|"       => "face-plain.png",
            ":("       => "face-sad.png",
            ":)"       => "face-smile.png",
            ":D"       => "face-smile-big.png",
            ":O"       => "face-surprise.png",
            ";)"  => "face-wink.png",
            ";-)" => "face-wink.png",
            ":idea:"   => "idea.png",
            ":love:"   => "love.png",
            ":music:"  => "music.png",
        );

        foreach ($emoticons as $emot => $image) {
            $body = str_replace($emot, "<img src=\"theme/{$GLOBALS["THEME"]}/images/icons/emoticons/{$image}\" align=\"absbottom\" width=\"16\" height=\"16\">", $body);
        }
        
        return $body;
    }

?>
I just got rid of the convertImages function. I added my code into convertBodyCodes.
 
0
•••
i dunno its not working :(
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Appraise.net
Escrow.com
Spaceship
Rexus Domain
CryptoExchange.com
Domain Recover
CatchDoms
NameMaxi - Your Domain Has Buyers
DomDB
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back