0

Hello Everyone,

I have some code which i use for BB codes in my forums. It works fine but I want to be able to not show the links if the user is not logged in. So below is the code I'm using for all BB codes used and the second piece of code is what i am aiming for but it doesn't work its just to make it clear as to what I would like help with.

Thanks in advance!

<?
function BBCode ($string) {
$search = array(
        '#\[b\](.*?)\[/b\]#',
        '#\[i\](.*?)\[/i\]#',
        '#\[u\](.*?)\[/u\]#',
		'#\[youtube\](.*?)\[/youtube\]#',
        '#\[img\](.*?)\[/img\]#',
        '#\[link=(.*?)\](.*?)\[/link\]#',
        '#\[code\](.*?)\[/code\]#'
);
$replace = array(
        '<b>\\1</b>',
        '<i>\\1</i>',
        '<u>\\1</u>',
		'<br /><br /><center><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/\\1?fs=1&amp;hl=en_US&amp;color1=0x234900&amp;color2=0x4e9e00"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/\\1?fs=1&amp;hl=en_US&amp;color1=0x234900&amp;color2=0x4e9e00" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="306"></embed></object></center><br /><br />',
        '<img src="\\1">',
        '<a href="\\1" target="_blank">\\2</a>',
        '<code>\\1</code>'
);
return preg_replace($search , $replace, $string);
}
?>
<?
function BBCode ($string) {
$search = array(
        '#\[b\](.*?)\[/b\]#',
        '#\[i\](.*?)\[/i\]#',
        '#\[u\](.*?)\[/u\]#',
		'#\[youtube\](.*?)\[/youtube\]#',
        '#\[img\](.*?)\[/img\]#',
        '#\[link=(.*?)\](.*?)\[/link\]#',
        '#\[code\](.*?)\[/code\]#'
);
$replace = array(
        '<b>\\1</b>',
        '<i>\\1</i>',
        '<u>\\1</u>',
		'<br /><br /><center><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/\\1?fs=1&amp;hl=en_US&amp;color1=0x234900&amp;color2=0x4e9e00"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/\\1?fs=1&amp;hl=en_US&amp;color1=0x234900&amp;color2=0x4e9e00" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="306"></embed></object></center><br /><br />',
        '<img src="\\1">',
        if($_COOKIE['userlogged'] == "") { echo "Login or register for links"; }else{ echo '<a href="\\1" target="_blank">\\2</a>'; },
        '<code>\\1</code>'
);
return preg_replace($search , $replace, $string);
}
?>

Edited by BlueCharge: n/a

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by BlueCharge
0

For anyone who ever has this problem the solution is below:

<?php
$replace = array(
    '0'=>'<b>\\1</b>','1'=>'<i>\\1</i>','2'=>'<u>\\1</u>','3'=>'<br /><br /><center><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/\\1?fs=1&amp;hl=en_US&amp;color1=0x234900&amp;color2=0x4e9e00"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/\\1?fs=1&amp;hl=en_US&amp;color1=0x234900&amp;color2=0x4e9e00" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="500" height="306"></embed></object></center><br /><br />','4'=>'<img src="\\1">','6'=>'<code>\\1</code>');

if($_COOKIE['userloggedin']==""){
    $replace['5'] ="Register for links";
}else{
    $replace['5'] = '<a href="\\1" target="_blank">\\2</a>';
}

?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.