[SOLVED]Combining Two Functions
Posted: Thu Aug 25, 2005 6:48 am
I have spent the last 5 hours trying to figure this one out and have failed,
so I come here for help
I'm working on creating custom BBCode that filters out all html and
only allows the tags I define. Once a user presses the submit button they
then see their post, which is the part that IS working.
I simply use the $_POST['formfieldname']
For a quick example of what I am talking about, make a test post at
http://www.vilificnews.info/dev/testsubmit.php
Ok, now the trouble I am having is when the article is pulled from the database.
I can't seem to get that to work alongside with my bb code replace.
A sample of a function that pulls the article from the database:
The function I am trying to use to allow for the custom tags to be shown
Any ideas how I can have the articles pulled from database to be written over with the
bbcode stuff?
so I come here for help
I'm working on creating custom BBCode that filters out all html and
only allows the tags I define. Once a user presses the submit button they
then see their post, which is the part that IS working.
I simply use the $_POST['formfieldname']
For a quick example of what I am talking about, make a test post at
http://www.vilificnews.info/dev/testsubmit.php
Ok, now the trouble I am having is when the article is pulled from the database.
I can't seem to get that to work alongside with my bb code replace.
A sample of a function that pulls the article from the database:
Code: Select all
function one_random_news_entry() {
$result = mysql_unbuffered_query("SELECT * FROM news ORDER BY RAND() LIMIT 1");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$newposts = array ( $row['name'] => "Name", $row['lova'] => "Past Loves", $row['news'] => "Bash" );
foreach ( $newposts as $postfield => $postinput )
{
echo "<b>$postinput:</b> $postfield<br>";
}
echo "<p> </p>";
}
}Code: Select all
function submitTags($html, $media=0, $font=0)
{
$html = preg_replace('#</?.*?\>#i','',$html);
$html = preg_replace('#<script[^>]*?>.*?</script>#i','',$html);
$html = htmlspecialchars($html);
if($media){
$html = preg_replace("#\[link\](.*?)\[/link\]#i", "<a href=\"\\1\" target=\"_blank\" title=\"bashmyex.com Bash Your Ex Girlfriend or Boyfriend Link!\">\\1</a>", $html);
$html = preg_replace("#\[img\](.*?)\[/img\]#i", "<img src=\"\\1\" border=\"0\" alt=\"bashmyex.com Bash Your Ex Girlfriend or Boyfriend Pic!\">", $html);
$html = preg_replace("#\[img url=(.*?)\](.*?)\[/img\]#i", "<a href=\"\\1\" target=\"_blank\"><img src=\"\\2\" border=\"0\" alt=\"bashmyex.com Bash Your Ex Girlfriend or Boyfriend Pic!\"></a>", $html);
}else{
$html = preg_replace("#\[link\](.*?)\[/link\]#i", "", $html);
$html = preg_replace("#\[img\](.*?)\[/img\]#i", "", $html);
$html = preg_replace("#\[img url=(.*?)\](.*?)\[/img\]#i", "", $html);
}
if($font)
$html = preg_replace("#\[br\]#i", "<br>", $html);
$html = preg_replace("#\[center\](.*?)\[/center\]#i", "<p align=\"center\">\\1 </p>", $html);
$html = preg_replace("#\[b\](.*?)\[/b\]#i", "<strong>\\1 </strong>", $html);
$html = preg_replace("#\[italic\](.*?)\[/italic\]#i", "<em>\\1 </em>", $html);
$html = preg_replace("#\[line\](.*?)\[/line\]#i", "<u>\\1 </u>", $html);
$html = preg_replace("#\[strike\](.*?)\[/strike\]#i", "<strike>\\1 </strike>", $html);
$html = preg_replace("#\[size=small\](.*?)\[/small\]#i", "<font size=\"1\">\\1 </font>", $html);
$html = preg_replace("#\[size=medium\](.*?)\[/medium\]#i", "<font size=\"4\">\\1 </font>", $html);
$html = preg_replace("#\[size=big\](.*?)\[/big\]#i", "<font size=\"6\">\\1 </font>", $html);
$html = preg_replace("#\[color=red\](.*?)\[/color\]#i", "<font color=\"#FF0000\">\\1 </font>", $html);
$html = preg_replace("#\[color=orange\](.*?)\[/color\]#i", "<font color=\"#FF6600\">\\1 </font>", $html);
$html = preg_replace("#\[color=blue\](.*?)\[/color\]#i", "<font color=\"#0000FF\">\\1 </font>", $html);
$html = preg_replace("#\[color=green\](.*?)\[/color\]#i", "<font color=\"#339966\">\\1 </font>", $html);
$html = preg_replace("#\[color=neon green\](.*?)\[/color\]#i", "<font color=\"00FF00\">\\1 </font>", $html);
$html = preg_replace("#\[color=black\](.*?)\[/color\]#i", "<font color=\"#000000\">\\1 </font>", $html);
$html = preg_replace("#\[color=pink\](.*?)\[/color\]#i", "<font color=\"#FF99cc\">\\1 </font>", $html);
return($html);
}
# test string
$viewname = defines what uses the above [tags] [/tags];
//example
$viewlova = $_POST['formfieldname'] ; //would define a part of a form to use the tags
$viewbash = defines what uses the above [tags] [/tags];
# conversion. combines the overall function and the defines from the immediate above variables
$viewname = submitTags($viewname, 1, 1);
$viewlova = submitTags($viewlova, 1, 1);
$viewbash = submitTags($viewbash, 1, 1);bbcode stuff?