Jump to content

[SOLVED] function help


DeanWhitehouse

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.