it's a simple method to turn html tags into bbcode:
here is a code:
Code: Select all
<?php
$str = "<b>Hello World</b>";
$pattern = "/(<)(bB)([^>]*>)/e";
$str = preg_replace($pattern,"'\\1'.'[b]'.'\\3'",$str);
echo $str;
?>And here is my html form in which i am trying to post data with bbcodes:
Code: Select all
<html>
<head><title>Comment Form</title></head>
<style type="text/css">
body {
border: 2% solid #dddddd;
margin: 4%;
padding: 4%;
}
.button {
border:1px inset #dddddd;
}
</style>
<body>
<center><form method="post" action="form.php">
<table border="1" cellpadding="2" cellspacing="0" width="75%" style="border-collapse:collapse;border-bottom:1px solid #dddddd;border-left:2px solid #ccc;border-right:2px solid #ccc;border-top:1px solid #dddddd;">
<tr><td><b>Enter Comments:</b></td><td><textarea name="comments"></textarea></td></tr>
<tr><td> </td><td><input type="submit" value="Submit" class="button"/> <input type="reset" value="Reset" class="button"/></td></tr>
</table>
</form></center>
</body>
</html>