Make Bold PHP Script Help

Discussion in 'Web Design and Development' started by JelvisChan, Dec 31, 2009.

  1. JelvisChan macrumors member

    Joined:
    Jan 9, 2009
    #1
    Another PHP Basic problem, if anyone could be so kind to shed some light...

    What I am trying to do is this:

    You have a form, and the action is to itself. And in order to process this form, there are a list of functions like filtering bad words, enabling styled text and whatnot.

    I want to add a checkbox in the form that asks if you want to make this post ( this is a form to post a topic ) bold and red font.

    This is what I have done thus far:

    The HTML:
    HTML:
    <form method=post action="message.php[COLOR="Red"](this file)[/COLOR]" name="form"><br>
    <p><input type="hidden" name="a" value="addnew"><b>Name:</b><br><input type=text name="name" size=30 maxlength=30><br>
    E-mail (optional):<br><input type=text name="email" size=30 maxlength=50><br>
    <b>Subject:</b><br><input type=text name="subject" size=30 maxlength=100><br><br>
    <b>Message:</b><br><textarea cols=50 rows=9 name="message"></textarea><br>
    Insert styled text: <a href="Javascript:insertspecial('B')"><b>Bold</b></a> |
    <a href="Javascript:insertspecial('I')"><i>Italic</i></a> |
    <a href="Javascript:insertspecial('U')"><u>Underlined</u></a> |<br>
    Is it an Important Topic? <input type="checkbox" name="important" value="important">
    
    The PHP Behind It:
    PHP:
    <?php 
    function filter_bad_words($text) {
    global 
    $settings;
    $file 'badwords/'.$settings['filter_lang'].'.php';

        if (
    file_exists($file))
        {
            include_once(
    $file);
        }
        else
        {
            
    problem("The bad words file ($file) can't be found! Please check the
            name of the file. On most servers names are CaSe SeNsiTiVe!"
    );
        }

        foreach (
    $settings['badwords'] as $k => $v)
        {
            
    $text preg_replace("/\b$k\b/i",$v,$text);
        }

    return 
    $text;
    // END filter_bad_words

    function addNewReply($name,$email,$subject,$comments,$orig_id,$orig_name,$orig_subject,$orig_date) {
    global 
    $settings;
    $date=date ("d/M/Y");


    $comments str_replace("\'","'",$comments);
    $comments str_replace("\"",""",$comments);
    $comments = MakeUrl($comments);
    $comments = str_replace("\r\n","<br>",$comments);
    $comments = str_replace("\n","<br>",$comments);
    $comments = str_replace("\r","<br>",$comments);

    /* Let's strip those slashes */
    $comments = stripslashes($comments);
    $subject = stripslashes($subject);
    $name = stripslashes($name);
    $orig_name = stripslashes($orig_name);
    $orig_subject = stripslashes($orig_subject);

    /* Make text bold, italic and underlined text */
    if (
    $_REQUEST['nostyled'] != "Y") {$comments=styledText($comments);}
    if (
    $_REQUEST['important'] == "important") {echo '<b>' + $name + '</b>';} 

    if (
    $settings['smileys'] == 1 && $_REQUEST['nosmileys'] != "Y") {$comments processsmileys($comments);}
    if (
    $email != "NO") {$mail "<<a href=\"mailto:$email\">$email</a>>";}
    else 
    {$mail=" ";}

    if (
    $settings['filter']) {
    $comments = filter_bad_words($comments);
    $name = filter_bad_words($name);
    $subject = filter_bad_words($subject);
    }

    $fp = fopen("count.txt","rb") or problem("Can't open the count file (count.txt) for reading!");
    $count=fread($fp,6);
    fclose($fp);
    $count++;
    $fp = fopen("count.txt","wb") or problem("Can'
    t open the count file (count.txt) for writingPlease CHMOD this file to 666 (rw-rw-rw)");
    if (flock(
    $fp, LOCK_EX)) {
        fputs(
    $fp,$count);
        flock(
    $fp, LOCK_UN);
    } else {
        echo "
    Error locking a fileplease try again later!";
    }
    fclose(
    $fp);

    $threads = file("threads.txt");

    for (
    $i=0;$i<=count($threads);$i++) {
        if(strstr(
    $threads[$i],'<!--o '.$orig_id.'-->'))
            {
            preg_match("
    /<\!--(.*)-->\s\((.*)\)/",$threads[$i],$matches);
            
    $number_of_replies=$matches[2];$number_of_replies++;
            
    $threads[$i] = "<!--o $orig_id--> ($number_of_replies)\n";
            
    $threads[$i] .= "<!--z $count-->\n";
            
    $threads[$i] .= "<!--s $count--><ul><li><a href=\"msg/$count.$settings[extension]\">$subject</a> - <b>$name</b> <i>$date</i>\n";
            
    $threads[$i] .= "<!--o $count--> (0)\n";
            
    $threads[$i] .= "</li></ul><!--k $count-->\n";
            break;
            }
    }

    $newthreads=implode('',$threads);

    $fp fopen("threads.txt","wb") or problem("Couldn't open links file (threads.txt) for writing! Please CHMOD it to 666 (rw-rw-rw)!");
    if (
    flock($fpLOCK_EX)) {
        
    fputs($fp,$newthreads);
        
    flock($fpLOCK_UN);
    } else {
        echo 
    "Error locking a file, please try again later!";
    }
    fclose($fp);

    $other "in reply to <a href=\"$orig_id.$settings[extension]\">$orig_subject</a> posted by $orig_name on $orig_date";
    createNewFile($name,$mail,$subject,$comments,$count,$date,$other,$orig_id);

    $oldfile="msg/".$orig_id.".".$settings['extension'];

    $filecontent file($oldfile);

    for (
    $i=0;$i<=count($filecontent);$i++) {
        if(
    preg_match("/<!-- zacni -->/",$filecontent[$i]))
            {
            
    $filecontent[$i] = "\n<!--s $count--><li><a href=\"$count.$settings[extension]\">$subject</a> - <b>$name</b> <i>$date</i></li>\n";
            break;
            }
    }

    $rewritefile=implode('',$filecontent);

    $fp fopen($oldfile,"wb") or problem("Couldn't open file $oldfile for writing! Please CHMOD the "msg" folder to 777 (rwx-rwx-rwx)!");
    if (
    flock($fpLOCK_EX)) {
        
    fputs($fp,$rewritefile);
        
    flock($fpLOCK_UN);
    } else {
        echo 
    "Error locking a file, please try again later!";
    }
    fclose($fp);

    ?>

    This doesn't work because the name part of the form is still just regular text and I want it to be bold.

    Is this possible with everything else staying the same?

    Jeff
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    Make sure to use $_POST and $_GET rather than $_REQUEST.

    You can use print_r() to see what's in the $_POST array as a simple test to see if the form info is being passed correctly.
     
  3. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #3
    Look here, threads.txt holds the topic details:

    Current PHP Processing Code:

    $threads = file("threads.txt");

    for ($i=0;$i<=count($threads);$i++) {
    if(strstr($threads[$i],'<!--o '.$orig_id.'-->'))
    {
    preg_match("/<\!--(.*)-->\s\((.*)\)/",$threads[$i],$matches);
    $number_of_replies=$matches[2];$number_of_replies++;
    $threads[$i] = "<!--o $orig_id--> ($number_of_replies)\n";
    $threads[$i] .= "<!--z $count-->\n";
    $threads[$i] .= "<!--s $count--><ul><li><a href=\"msg/$count.$settings[extension]\">$subject</a> - <b>$name</b> <i>$date</i>\n";
    $threads[$i] .= "<!--o $count--> (0)\n";
    $threads[$i] .= "</li></ul><!--k $count-->\n";
    break;
    }


    IS THERE A WAY TO MAKE IT SO THAT IF THE IMPORTANT CHECKBOX IS CHECKED, $subject IS BOLD AND RED?

    I have tried this:

    elseif ($_REQUEST['important'] == "important") {
    preg_match("/<\!--(.*)-->\s\((.*)\)/",$threads[$i],$matches);
    $number_of_replies=$matches[2];$number_of_replies++;
    $threads[$i] = "<!--o $orig_id--> ($number_of_replies)\n";
    $threads[$i] .= "<!--z $count-->\n";
    $threads[$i] .= "<!--s $count--><ul><li><a href=\"msg/$count.$settings[extension]\"><b><font color=\"#cc0000\">$subject</font></b></a> - <b>$name</b> <i>$date</i>\n";
    $threads[$i] .= "<!--o $count--> (0)\n";
    $threads[$i] .= "</li></ul><!--k $count-->\n";
    break;
    }
    , but it doesn't work.

    Any ideas?
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
  5. JelvisChan thread starter macrumors member

    Joined:
    Jan 9, 2009
    #5
    Yes I know, I did, but it doesn't do what I want.

    I am basically wanting the topic subject to be bold, only if the checkbox is checked.

    It is not working.
     

Share This Page