Jump to content

Recommended Posts

i have created this function

<?php 
function bbcode($code)
{
$str = preg_replace("/\[center\](.*?)\[\/center\]/","<center>\\1</center>",$code);
$str = preg_replace("/\[b\](.*?)\[\/b\]/","<b>\\1</b>",$code);
$str = preg_replace("/\<center\>(.*?)\<\/center\>/","<center>\\1</center>",$code);
echo $str;
}
bbcode("
[center]1[/center]
");
echo "2";
?>

But all this does is echo the string , in this case

[center]1[/center]

but it should echo out 1 centered. like below , any one have any ideas, is my function wrong?

1

Link to comment
https://forums.phpfreaks.com/topic/115462-solved-function-help/
Share on other sites

i don't want to make a new thread, so here it is

in my bbcode i want to allow certain html to be allowed, 2 things, is this an ok thing to do or should i totally disble it

and how would i limit it to only allowing certain html to be in the string e.g. <center>

Link to comment
https://forums.phpfreaks.com/topic/115462-solved-function-help/#findComment-593642
Share on other sites

soz, don't want to start another thread again.

Is there anyway i can get the what is wrote after the eqauls sign, i am making bbcode and need it for link etc.

e.g.

[ link = ]Cake[ /link]

 

this is my code so far

<?php 
function bbcode($code)
{
//colors, links, images,email,quotes,block
//marquee
$code = preg_replace("/\[scroll\](.*?)\[\/scroll\]/","<marquee>\\1</marquee>",$code);
//user
$code = preg_replace("/\[user\](.*?)\[\/user\]/","<a href=''>\\1</a>",$code);
//strong
$code = preg_replace("/\[strong\](.*?)\[\/strong\]/","<strong>\\1</strong>",$code);
//definition list
$code = preg_replace("/\[dlist\](.*?)\[\/dlist\]/","<dl>\\1</dl>",$code);
//term
$code = preg_replace("/\[term\](.*?)\[\/term\]/","<dt>\\1</dt>",$code);
//definition
$code = preg_replace("/\[def\](.*?)\[\/def\]/","<dd>\\1</dd>",$code);

//unorganized list
$code = preg_replace("/\[ulist\](.*?)\[\/ulist\]/","<ul>\\1</ul>",$code);
//organized list
$code = preg_replace("/\[olist\](.*?)\[\/olist\]/","<ol>\\1</ol>",$code);
//list item
$code = preg_replace("/\[item\](.*?)\[\/item\]/","<li>\\1</li>",$code);
//sub
$code = preg_replace("/\[sup\](.*?)\[\/sup\]/","<sup>\\1</sup>",$code);
//super
$code = preg_replace("/\[sub\](.*?)\[\/sub\]/","<sub>\\1</sub>",$code);
//pre
$code = preg_replace("/\[pre\](.*?)\[\/pre\]/","<pre>\\1</pre>",$code);
//emphazied
$code = preg_replace("/\[em\](.*?)\[\/em\]/","<em>\\1</em>",$code);
//italic
$code = preg_replace("/\[i\](.*?)\[\/i\]/","<i>\\1</i>",$code);
//strikethrough
$code = preg_replace("/\[s\](.*?)\[\/s\]/","<del>\\1</del>",$code);
//bold
$code = preg_replace("/\[b\](.*?)\[\/b\]/","<b>\\1</b>",$code);
$code = preg_replace("/\<b\>(.*?)\<\/b\>/","<b>\\1</b>",$code);
//center
$code = preg_replace("/\[center\](.*?)\[\/center\]/","<center>\\1</center>",$code);

echo $code;
}
bbcode("[scroll]scroll[/scroll]<br/>");
bbcode("
[center]center[/center]
<br/>");
bbcode("[b]Bold[/b]<br/>");
bbcode("[s]Strikout[/s]<br/>");
bbcode("[i]Italic[/i]<br/>");
bbcode("[em]Emphazied[/em]<br/>");
bbcode("[pre]Pre[/pre]<br/>");
bbcode("[sup]Super[/sup]<br/>");
bbcode("[sub]Sub[/sub]<br/>");
bbcode("[ulist][item]Unorganized list[/item][/ulist]<br/>");
bbcode("[olist][item]Organized[/item][item]list[/item][/olist]<br/>");
bbcode("[dlist][term]Term[/term][def]Definition[/def][/dlist]<br/>");
bbcode("[strong]Strong[/strong]<br/>");
bbcode("[user]User[/user]<br/>");
?>
<script type="text/javascript">
function preview()
{
var current = document.getElementById("current").value;
document.getElementById("preview").innerHTML = current;
}
function insert(start,end)
{
var current = document.getElementById("current").value;
var code = prompt("Enter Value for "+start+end+" tags");
if (code!=null && code!="")
 {
document.getElementById("current").value += start+code+end;
 }
 else if(code == "")
 {
 		document.getElementById("current").value += start+end;
 }  
}
</script>
<textarea id="current" onKeyUp="preview();" rows="10" cols="50"></textarea><br/>
<span onClick="insert('[b]','[/b]')" style="cursor:pointer;"> Bold </span><span style="cursor:pointer;" onClick="insert('[i]','[/i]')"> Italic </span><span style="cursor:pointer;" onClick="insert('[s]','[/s]')"> Strikeout </span>
<div id="preview"></div>

Link to comment
https://forums.phpfreaks.com/topic/115462-solved-function-help/#findComment-593738
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.