SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 62
  1. #1
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question how to add faces, highlight code and dotted underline to my blog form?

    Hi I was wondering is it possible to improve my blog entry form almost exactly how you post an entry into this forum?
    Code:
    Where you can highlight code
    , use faces and add images

    I made my blog using codegrrl's build a blog tutorials

    If anyone knows if its possible and how to do it then please let me know!!

    My blog entry form accepts basic html like <b> and <i> and today I saw some words with a dotted underline and I really want to know if I can add this to words in my blog.
    On the link below scoll down to version 2.0 and you can see words with a dotted underline
    http://codegrrl.com/!/scripts/view/phpaskit/
    In the source I found this by the words that have the dotted underline
    <acronym title="Internet Protocol">IP</acronym>

    Im probably asking too much but if anyone knows how too add a dotted underline for words in my blog entrys aswel as faces and hightlight code then please let me know!!!

    Thanks!

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have just built a forum at work and I used javascript to insert whatever the user chooses into the text box, the str_replace to search for it all and change it to image tags and the correct image
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  3. #3
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I found this in the manual http://uk2.php.net/str_replace

    have you got a tutorial or something please?

  4. #4
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Give me a few mins and Ill grab the code I wrote to handle it all, brb
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  5. #5
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok ill try and make this as easy as possible, ill show you an example of one emoticon (a smiley) but bear in mind you can add to them by changing a few simple things.

    This is the code i have for a say a smiling face:

    HTML Code:
    <img src="../images/icons/emoticons/smiling.gif" onClick="addsmiley(':smile:')">
    That displays the face for the user to click on, you can create as many as you need for each emoticon, now we want to create a javascript function to handle the onClick event. Code:

    HTML Code:
    function addsmiley(string) {
    
    	var newtext = string;
    	document.addthread.message.value += newtext;
    	document.addthread.message.focus();
    	return;
    	
    }
    addthread is the name of the form and is required and message is the name of the textarea and is also required.

    That will put this in the users textarea ":smile:", I'll presume you can get it into the database. Now is the section where we search for all the smileys:

    PHP Code:
    function smiley($content) {

        
    $find[] = ":smile:";
        
    $replace[] = "<img src='images/icons/emoticons/smiling.gif' alt='smile'>";

        echo 
    str_replace($find$replace$content);


    That is the function that you use to search for the smiley, you will need to a find[] and replace[] for each smiley you want, so for instance i have some content out of the database and I would print it to the screen like this:
    PHP Code:
    echo smiley($mycontent); 
    That will search the content and replace every occurance of ":smile:" with a

    Let me know if you need any more help
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  6. #6
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok great this looks brilliant! Ill let you know when i've played around!
    Thanks!

  7. #7
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cant get it to work. The javascript is at the top and I put the php inside the textarea.
    I see the smiley face on my entry page but I can't click on it and so it doesnt add to the textarea.

    I posted :smile: and the blog entry appeared as :smile: and not a
    Do I have to put this code on my index aswel?

    Below is all the code to my blog entry page. Maybe you can see something I've done wrong?
    Thanks! I cant wait to get this working!!!

    PHP Code:
    <script type="text/javascript">
    function addsmiley(string) {

        var newtext = string;
        document.addthread.message.value += newtext;
        document.addthread.message.focus();
        return;
        
    }
    </script>

    <?php
    $current_month 
    date("F");
    $current_date date("d");
    $current_year date("Y");
    $current_time date("H:i");

    if (isset(
    $_POST['submit'])) {

        
    $month htmlspecialchars(strip_tags($_POST['month']));
        
    $date htmlspecialchars(strip_tags($_POST['date']));
        
    $year htmlspecialchars(strip_tags($_POST['year']));
        
    $time htmlspecialchars(strip_tags($_POST['time']));
        
    $title htmlspecialchars(strip_tags($_POST['title']));
        
    $entry $_POST['entry'];
        
    $password htmlspecialchars(strip_tags($_POST['password']));
        
        
    $timestamp strtotime($month " " $date " " $year " " $time);

        
    $entry nl2br($entry);

        if (!
    get_magic_quotes_gpc()) {
            
    $title addslashes($title);
            
    $entry addslashes($entry);
        }

        
    mysql_connect ('localhost''username''password') ;
        
    mysql_select_db ('hullweb_jgardner');

        
    $sql "INSERT INTO php_blog (timestamp,title,entry,password) VALUES ('$timestamp','$title','$entry','$password')";

        
    $result mysql_query($sql) or print("Can't insert into table php_blog.<br />" $sql "<br />" mysql_error());

        if (
    $result != false) {
            print 
    "Your entry has successfully been entered into the database.";
        }

        
    mysql_close();
    }
    ?>

    <form method="post" action="<?php echo $_SERVER['../PHP_SELF']; ?>">

    <p><strong><label for="month">Date (month, day, year):</label></strong> 

    <select name="month" id="month">
    <option value="<?php echo $current_month?>"><?php echo $current_month?></option>
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select>

    <input type="text" name="date" id="date" size="2" value="<?php echo $current_date?>" />

    <select name="year" id="year">
    <option value="<?php echo $current_year?>"><?php echo $current_year?></option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2008</option>
    <option value="2010">2010</option>
    </select>

    <strong><label for="time">Time:</label></strong> <input type="text" name="time" id="time" size="5" value="<?php echo $current_time?>" /></p>

    <p><strong><label for="title">Title:</label></strong> <input type="text" name="title" name="title" size="40" /></p>

    <img src="../images/smiling.gif" width="15" height="15" onClick="addsmiley(':smile:')"> 


    <p><strong><label for="password">Password protect?</label></strong> <input type="checkbox" name="password" id="password" value="1" /></p>


    <p><textarea cols="80" rows="20" name="entry" id="entry">

    <?php function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);
    }  

    echo 
    smiley($mycontent);

    ?>


    </textarea></p>

    <p><input type="submit" name="submit" id="submit" value="Submit"></p>

    </form>

  8. #8
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The face will not appear in the text area only the :smile:, this is the only way to really do this without things getting to complex.

    The function "addsmiley" needs to go at the top of the page and is not required when entering text into the text area. You use the smiley function when you are displaying the content inputed by the text area, so:

    Text Area-->Insert Into Database-->Pull Data From DB -->addsmiley($displaycontent)

    Here is a list of exactly what you need to do.

    1)Add a form name to your form called "addthread" (name="addthread"), this is required for the javascript to know what form to change the value in

    2)Change your textarea name to "message" (<textarea name="message">) This is also needed for the javascript to know where the new value is to be placed

    3)Keep the smiley img where it is

    4)Move the addsmiley() function to the top of the page you are showing the blog entry on.

    5)Get the results from the database and the one with the smileys in, put inside the addsmiley() function i.e addsmiley($content_from_db)

    In addition to these you need to make sure you have the correct paths for the image folder and have an image called smiley.jpg in there.

    If you still have problems let me know and I will help out and also please post the code for the page you are displaying the blog entry on that way i can tell you where to put things.
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  9. #9
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol keep the smiley img where it is.. I got one thing right :-D
    when Ive done as much as I can Ill let you know thanks!

  10. #10
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im still trying to edit my entry form once I've done it I will reply with results!

    Heres the code to where my entrys are displayed. Ive added your php at the top (step 4).

    PHP Code:
    <?php function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);
    }  

    echo 
    smiley($mycontent);

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>

    <title>Home Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />    

    <link href="css/main.css" rel="stylesheet" type="text/css" />

    </head>

    <body>

    <div id="container">

    <div id="main_text">

    <?php

    mysql_connect 
    ('localhost''username''password') ;
    mysql_select_db ('hullweb_user');

    if(!isset(
    $_GET['page'])){
        
    $page 1;
    } else {
        
    $page $_GET['page'];
    }


    $sql "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT $from$max_results";
    $result mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" $sql "<br />" mysql_error()); 

    while(
    $row mysql_fetch_array($result)) {

        
    $date date("l F d Y"$row['timestamp']);

        
    $title stripslashes($row['title']);
        
    $entry stripslashes($row['entry']);
        
    $password $row['password'];
        
    $id $row['id'];

        if (
    $password == 1) {
            echo 
    "<p><span>" $title "</span></p><br />";

            
    printf("This is a password protected entry. If you have a password, log in below.");

            
    printf("<form method=\"post\" action=\"entry/journal.php?id=%s\"> <label for=\"username\">Username:</label><input type=\"text\" name=\"username\" id=\"username\" /><label for=\"pass\">Password:</label><input type=\"password\" name=\"pass\" id=\"pass\" /></p><p><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" /></p></form><br />",$id);
            print 
    "<hr />";
        }
        else { 
    ?>    
             
            
              
              <p class="blogtitle"> <span class="blogtit"><?php echo $title?></span></p><br />
                        <?php echo $entry?><br /><br />
                Posted on <?php echo $date?>


            
            <?php 

            $result2 
    mysql_query ("SELECT id FROM php_blog_comments WHERE entry='$id'");
            
    $num_rows mysql_num_rows($result2);

            if (
    $num_rows 0) {
                echo 
    "<a href=\"entry/journal.php?id=" $id "\">" $num_rows " comments</a>";
            }
            else {
                echo 
    "<a href=\"entry/journal.php?id=" $id "\">Leave a comment</a>";
            } 
    ?>
            <hr class="hr3" /><br />

            <?php
        
    }
    }

    ?> 


    </div>

    </div>
    </body>
    </html>
    Last edited by shtoom; Feb 4, 2007 at 00:15.

  11. #11
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I dont think ive been able to do step 1 successfully..
    I think I did step 2 correct.
    I know step 3 is ok lol
    I think step 4 is right
    Im not sure about step 5..

    Heres my new blog entry code:
    PHP Code:

    <script type="text/javascript">
    function addsmiley(string) {

        var newtext = string;
        document.addthread.message.value += newtext;
        document.addthread.message.focus();
        return;
        
    }
    </script>

    <?php
    $current_month 
    date("F");
    $current_date date("d");
    $current_year date("Y");
    $current_time date("H:i");

    if (isset(
    $_POST['submit'])) {

        
    $month htmlspecialchars(strip_tags($_POST['month']));
        
    $date htmlspecialchars(strip_tags($_POST['date']));
        
    $year htmlspecialchars(strip_tags($_POST['year']));
        
    $time htmlspecialchars(strip_tags($_POST['time']));
        
    $title htmlspecialchars(strip_tags($_POST['title']));
        
    $entry $_POST['entry'];
        
    $password htmlspecialchars(strip_tags($_POST['password']));
        
        
    $timestamp strtotime($month " " $date " " $year " " $time);

        
    $entry nl2br($entry);

        if (!
    get_magic_quotes_gpc()) {
            
    $title addslashes($title);
            
    $entry addslashes($entry);
        }

        
    mysql_connect ('localhost''username''password') ;
        
    mysql_select_db ('user_name');

        
    $sql "INSERT INTO php_blog (timestamp,title,entry,password) VALUES ('$timestamp','$title','$entry','$password')";

        
    $result mysql_query($sql) or print("Can't insert into table php_blog.<br />" $sql "<br />" mysql_error());

        if (
    $result != false) {
            print 
    "Your entry has successfully been entered into the database.";
        }

        
    mysql_close();
    }
    ?>

    <form method="post" action="<?php echo $_SERVER['../PHP_SELF']; ?>">

    <p><strong><label for="month">Date (month, day, year):</label></strong> 

    <select name="month" id="month">
    <option value="<?php echo $current_month?>"><?php echo $current_month?></option>
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select>

    <input type="text" name="date" id="date" size="2" value="<?php echo $current_date?>" />

    <select name="year" id="year">
    <option value="<?php echo $current_year?>"><?php echo $current_year?></option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2008</option>
    <option value="2010">2010</option>
    </select>

    <strong><label for="time">Time:</label></strong> <input type="text" name="time" id="time" size="5" value="<?php echo $current_time?>" /></p>

    <p><strong><label for="title">Title:</label></strong> <input type="text" name="title" name="title" size="40" /></p>

    <form name="addthread"></form>

    <img src="../images/smiling.gif" width="15" height="15" onClick="addsmiley(':smile:')"> 


    <p><strong><label for="password">Password protect?</label></strong> <input type="checkbox" name="password" id="password" value="1" /></p>


    <p><textarea name="message" cols="80" rows="20" name="entry" id="entry">

    </textarea></p>

    <p><input type="submit" name="submit" id="submit" value="Submit"></p>

    </form>

  12. #12
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <script type="text/javascript">
    function addsmiley(string) {

        var newtext = string;
        document.addthread.message.value += newtext;
        document.addthread.message.focus();
        return;
        
    }
    </script>

    <?php
    $current_month 
    date("F");
    $current_date date("d");
    $current_year date("Y");
    $current_time date("H:i");

    if (isset(
    $_POST['submit'])) {

        
    $month htmlspecialchars(strip_tags($_POST['month']));
        
    $date htmlspecialchars(strip_tags($_POST['date']));
        
    $year htmlspecialchars(strip_tags($_POST['year']));
        
    $time htmlspecialchars(strip_tags($_POST['time']));
        
    $title htmlspecialchars(strip_tags($_POST['title']));
        
    $entry $_POST['entry'];
        
    $password htmlspecialchars(strip_tags($_POST['password']));
        
        
    $timestamp strtotime($month " " $date " " $year " " $time);

        
    $entry nl2br($entry);

        if (!
    get_magic_quotes_gpc()) {
            
    $title addslashes($title);
            
    $entry addslashes($entry);
        }

        
    mysql_connect ('localhost''username''password') ;
        
    mysql_select_db ('user_name');

        
    $sql "INSERT INTO php_blog (timestamp,title,entry,password) VALUES ('$timestamp','$title','$entry','$password')";

        
    $result mysql_query($sql) or print("Can't insert into table php_blog.<br />" $sql "<br />" mysql_error());

        if (
    $result != false) {
            print 
    "Your entry has successfully been entered into the database.";
        }

        
    mysql_close();
    }
    ?>

    <form name="addthread" method="post" action="<?php echo $_SERVER['../PHP_SELF']; ?>">

    <p><strong><label for="month">Date (month, day, year):</label></strong>

    <select name="month" id="month">
    <option value="<?php echo $current_month?>"><?php echo $current_month?></option>
    <option value="January">January</option>
    <option value="February">February</option>
    <option value="March">March</option>
    <option value="April">April</option>
    <option value="May">May</option>
    <option value="June">June</option>
    <option value="July">July</option>
    <option value="August">August</option>
    <option value="September">September</option>
    <option value="October">October</option>
    <option value="November">November</option>
    <option value="December">December</option>
    </select>

    <input type="text" name="date" id="date" size="2" value="<?php echo $current_date?>" />

    <select name="year" id="year">
    <option value="<?php echo $current_year?>"><?php echo $current_year?></option>
    <option value="2004">2004</option>
    <option value="2005">2005</option>
    <option value="2006">2006</option>
    <option value="2007">2007</option>
    <option value="2008">2008</option>
    <option value="2009">2008</option>
    <option value="2010">2010</option>
    </select>

    <strong><label for="time">Time:</label></strong> <input type="text" name="time" id="time" size="5" value="<?php echo $current_time?>" /></p>

    <p><strong><label for="title">Title:</label></strong> <input type="text" name="title" name="title" size="40" /></p>

    <form name="addthread"></form>

    <img src="../images/smiling.gif" width="15" height="15" onClick="addsmiley(':smile:')">


    <p><strong><label for="password">Password protect?</label></strong> <input type="checkbox" name="password" id="password" value="1" /></p>


    <p><textarea name="message" cols="80" rows="20" name="entry" id="message">

    </textarea></p>

    <p><input type="submit" name="submit" id="submit" value="Submit"></p>

    </form>
    Ok I have made the changes to the script, i have added the form name and also changed the id of the textarea to message as well as the name. Now on the page that you need to show the smiley on (the display page) put my php addsmiley function at the top and wrap the content variable in it.
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  13. #13
    SitePoint Zealot chrisdpucci's Avatar
    Join Date
    Dec 2006
    Location
    On the internets
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If your form uses a standard textarea tag, there are lots of really good wysiwyg editors that you can embed into your forms. Do a quick search on the forums and you'll find alot of helpful information. One that seems to be a favorite is Textarea Pro:

    http://www.perfectscripts.com/detail...yg-editor.html

    The one I use most is Wysiwyg Pro which works really well. Only two problems with it, one it's not free and two it doesn't work in Safari, (you get a plain textarea in safari). It's still a really good wysiwyg add on though.

    http://www.wysiwygpro.com/

    Hope this helps,

    Chris

  14. #14
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    webnoob I dont think i've done the display page code correct I put the following at the top and now new entry's cant be displayed. The entry page works because I can click on the face and it appears in the text area

    PHP Code:
    <?php function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);
    }  

    echo 
    smiley($mycontent);

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>

    <title>Home Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />    

    <link href="css/main.css" rel="stylesheet" type="text/css" />

    </head>

    <body>

    <div id="container">

    <div id="main_text">

    <?php

    mysql_connect 
    ('localhost''username''password') ;
    mysql_select_db ('hullweb_user');

    if(!isset(
    $_GET['page'])){
        
    $page 1;
    } else {
        
    $page $_GET['page'];
    }


    $sql "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT $from$max_results";
    $result mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" $sql "<br />" mysql_error());

    while(
    $row mysql_fetch_array($result)) {

        
    $date date("l F d Y"$row['timestamp']);

        
    $title stripslashes($row['title']);
        
    $entry stripslashes($row['entry']);
        
    $password $row['password'];
        
    $id $row['id'];

        if (
    $password == 1) {
            echo 
    "<p><span>" $title "</span></p><br />";

            
    printf("This is a password protected entry. If you have a password, log in below.");

            
    printf("<form method=\"post\" action=\"entry/journal.php?id=%s\"> <label for=\"username\">Username:</label><input type=\"text\" name=\"username\" id=\"username\" /><label for=\"pass\">Password:</label><input type=\"password\" name=\"pass\" id=\"pass\" /></p><p><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" /></p></form><br />",$id);
            print 
    "<hr />";
        }
        else { 
    ?>    
             
            
              
              <p class="blogtitle"> <span class="blogtit"><?php echo $title?></span></p><br />
                        <?php echo $entry?><br /><br />
                Posted on <?php echo $date?>


            
            <?php

            $result2 
    mysql_query ("SELECT id FROM php_blog_comments WHERE entry='$id'");
            
    $num_rows mysql_num_rows($result2);

            if (
    $num_rows 0) {
                echo 
    "<a href=\"entry/journal.php?id=" $id "\">" $num_rows " comments</a>";
            }
            else {
                echo 
    "<a href=\"entry/journal.php?id=" $id "\">Leave a comment</a>";
            } 
    ?>
            <hr class="hr3" /><br />

            <?php
        
    }
    }

    ?>


    </div>

    </div>
    </body>
    </html>
    Thanks for the info chrisdpuci I briefly looked but I won't delve into right now Id like learn what webnoob is teaching me!

  15. #15
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK here is the updated code followed by an explanation of the changes I have made:

    PHP Code:
    <?php function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);
    }  

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>

    <title>Home Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />    

    <link href="css/main.css" rel="stylesheet" type="text/css" />

    </head>

    <body>

    <div id="container">

    <div id="main_text">

    <?php

    mysql_connect 
    ('localhost''username''password') ;
    mysql_select_db ('hullweb_user');

    if(!isset(
    $_GET['page'])){
        
    $page 1;
    } else {
        
    $page $_GET['page'];
    }


    $sql "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT $from$max_results";
    $result mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" $sql "<br />" mysql_error());

    while(
    $row mysql_fetch_array($result)) {

        
    $date date("l F d Y"$row['timestamp']);

        
    $title stripslashes($row['title']);
        
    $entry stripslashes($row['entry']);
        
    $password $row['password'];
        
    $id $row['id'];

        if (
    $password == 1) {
            echo 
    "<p><span>" $title "</span></p><br />";

            
    printf("This is a password protected entry. If you have a password, log in below.");

            
    printf("<form method=\"post\" action=\"entry/journal.php?id=%s\"> <label for=\"username\">Username:</label><input type=\"text\" name=\"username\" id=\"username\" /><label for=\"pass\">Password:</label><input type=\"password\" name=\"pass\" id=\"pass\" /></p><p><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" /></p></form><br />",$id);
            print 
    "<hr />";
        }
        else { 
    ?>    
             
            
              
              <p class="blogtitle"> <span class="blogtit"><?php echo $title?></span></p><br />
                        <?php echo smiley($entry); ?><br /><br />
                Posted on <?php echo $date?>


            
            <?php

            $result2 
    mysql_query ("SELECT id FROM php_blog_comments WHERE entry='$id'");
            
    $num_rows mysql_num_rows($result2);

            if (
    $num_rows 0) {
                echo 
    "<a href=\"entry/journal.php?id=" $id "\">" $num_rows " comments</a>";
            }
            else {
                echo 
    "<a href=\"entry/journal.php?id=" $id "\">Leave a comment</a>";
            } 
    ?>
            <hr class="hr3" /><br />

            <?php
        
    }
    }
    OK, first of all I took out the echo statement in the function, that was there as an example.

    I have presumed that the $entry variable was the content with the smiley in it. So as a basic explanation as to how and why this works, the function smiley was added to the top of the page, this is the function, nothing else:

    PHP Code:
    <?php
    function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);
    }  
    ?>
    Now you can see here the function and then the function name, after the function name there are 2 brackets with a variable in, so when we call the function smiley() whatever we put in between the brackets will be looked through to search for smiley's. SO all you have to so is have the function at the top of the page and then when you want to use it on some content do this:

    PHP Code:
    <?php
    echo smiley($content_from_db);
    ?>
    That should work now, all the examples I have given should be sifficient to get the code to work, if you have any troubles look into some tutorials on functions and let me know.
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  16. #16
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    should I change content to entry?

    ive added what you told me and nothing appears in the entry..

    the topic title shows but the entry details dont

    see my website
    http://www.newmedia.lincoln.ac.uk/jecgardner/

  17. #17
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I changed $content to $entry but that didnt work.

    I have this at the top of my home page that displays my blog entrys
    PHP Code:
    <?php
    echo smiley($content_from_db);
    ?> 
    <?php
    function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);
    }  
    ?>
    Last edited by shtoom; Feb 5, 2007 at 03:54.

  18. #18
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The function needs to stay as it is. Just place it at the top of the page. Like this:

    PHP Code:
    <?php
    function smiley($content) {
    $find[] = ":smile:";
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
    echo 
    str_replace($find$replace$content);
    }
    ?>
    Right, get the variable that you echo out for the content and put it inside the smiley function like this:

    PHP Code:
    echo smiley(PUT YOUR CONTENT VARIABLE HERE
    That is all you need to do.
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  19. #19
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Theres a problem tho the blog title shows but the content for the entry doesnt.. Click here to see my website You can see the title smiley face test 2 but underneath no content shows..

    This is what I put at the top of the display page

    PHP Code:
    <?php
    function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);
    }  

    echo 
    smiley($entry);

    ?>

  20. #20
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why is this line at the top:

    PHP Code:
    echo smiley($entry); 
    All you need at the top is this:

    PHP Code:
    <?php
    function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);

    ?>
    Nothing else at all, no echo's, nothing.

    Ok, with that at the top of your page (dont add anything to it) get the variable with your content from the database and use the smiley function around it. So:


    Put this on the page where you want to show your content:

    PHP Code:
    echo smiley(VARIABLE FOR CONTENT FROM DATABASE HERE); 
    I cant really make it any clearer than that. Let me know if you have any problems.
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  21. #21
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Something isnt right because the title for the blog entrys show but the content where the smiley faces dont show..
    If I enter just text and no :smile: the entry still doesnt display..

    I've added the code to my best knowledge in the right place...

    Heres a review of my display page code.. Ive added
    PHP Code:
    <?php echo smiley($entry);  ?>
    just after
    PHP Code:
    <?php echo $title?>
    PHP Code:

    <?php function smiley($content) {
        
    $find[] = ":smile:";
        
    $replace[] = "<img src='../images/smiling.gif' alt='smile'>";
        echo 
    str_replace($find$replace$content);
    }  

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
    <head>

    <title>Home Page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />    

    <link href="css/main.css" rel="stylesheet" type="text/css" />

    </head>

    <body>

    <div id="container">

    <div id="main_text">

    <?php

    mysql_connect 
    ('localhost''username''password') ;
    mysql_select_db ('hullweb_user');

    if(!isset(
    $_GET['page'])){
        
    $page 1;
    } else {
        
    $page $_GET['page'];
    }


    $sql "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT $from$max_results";
    $result mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" $sql "<br />" mysql_error());

    while(
    $row mysql_fetch_array($result)) {

        
    $date date("l F d Y"$row['timestamp']);

        
    $title stripslashes($row['title']);
        
    $entry stripslashes($row['entry']);
        
    $password $row['password'];
        
    $id $row['id'];

        if (
    $password == 1) {
            echo 
    "<p><span>" $title "</span></p><br />";

            
    printf("This is a password protected entry. If you have a password, log in below.");

            
    printf("<form method=\"post\" action=\"entry/journal.php?id=%s\"> <label for=\"username\">Username:</label><input type=\"text\" name=\"username\" id=\"username\" /><label for=\"pass\">Password:</label><input type=\"password\" name=\"pass\" id=\"pass\" /></p><p><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" /></p></form><br />",$id);
            print 
    "<hr />";
        }
        else { 
    ?>    
             
     <p class="blogtitle"> <span class="blogtit">

    <?php echo $title?></span></p><br />
                       
     <?php echo smiley($entry);  ?> 

    <br /><br />
                
    Posted on <?php echo $date?>

          
            <?php

            $result2 
    mysql_query ("SELECT id FROM php_blog_comments WHERE entry='$id'");
            
    $num_rows mysql_num_rows($result2);

            if (
    $num_rows 0) {
                echo 
    "<a href=\"entry/journal.php?id=" $id "\">" $num_rows " comments</a>";
            }
            else {
                echo 
    "<a href=\"entry/journal.php?id=" $id "\">Leave a comment</a>";
            } 
    ?>
            <hr class="hr3" /><br />

            <?php
        
    }
    }

    ?>


    </div>

    </div>
    </body>
    </html>

  22. #22
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you echo the $entry normally, (without the function) does it show??
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  23. #23
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no

  24. #24
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, check the field in the database and make sure there is some content in there. Then get back to me
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  25. #25
    SitePoint Addict
    Join Date
    Dec 2006
    Posts
    378
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Slight improvement.. Now on my blog you can see smile in the content under the title. I entered into :smile: into the blog form and just the word 'smile' appears on the display page and no image.. hmm
    You can right click the text and it think its an image lol

    Ok its working!!!!!!

    I changed the path to the smiley face image for some reason the display page wasnt finding ../images/smiling.gif this path is used on the blog form. I changed the path too '../jecgardner/images/smiling.gif' and it works!!

    Thanks for your help webnoob! Hopefuly I can add my own images now

    Any advice on how to add a second and third image (im sure I can figure this one out)?

    Just wondering a few more thing tho if its ok to ask :-p
    Is it possible to make a word have a dotted unline like making the word bold and italic? How would I add these options + adding the
    Code:
    code
    option?? This would be amazing! Im still amazed the smiley face works!!!

    Thanks again!
    Last edited by shtoom; Feb 5, 2007 at 12:25.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •