SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2008
    Location
    Plano, TX
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding tags in text area

    I've built a small program that's prettymuch stores code snippets for me to view later if I need to use them. what i'm trying to do is get it to where when i press enter in the field it makes it to where it will display the enters in the results. i'm using htmlspecialchars() to make html tags act like regular text so I can't use <br /> to make the new line. how would i do this.

    here's my code but what javascript do i need to do this
    PHP Code:
    // insert into db
    if($save) {
    $code htmlspecialchars($_POST['code']);
    mysql_query("INSERT INTO $codepad (`name`, `code`) VALUES ('$namecode', '$code')");
    }
    // call from db
    if($find != '') {
    $results mysql_query("SELECT * FROM $codepad WHERE name LIKE '%$name%'");
    } else {
    $results mysql_query("SELECT * FROM $codepad");
    }
    // display from db
    echo "<table cellspacing='5px'>";
    $codenum =1;
    while(
    $row mysql_fetch_array($results)) {
        if(
    $codenum%== 1) { 
        echo 
    "<tr bgcolor='#FFFFCC'><td align='right'>".$codenum.". ".$row['name']."</td><td align='left'>".$row['code']."</td></tr>";
        
    $codenum++;
        } else {
        echo 
    "<tr bgcolor='#FFFFFF'><td align='right'>".$codenum.". ".$row['name']."</td><td align='left'>".$row['code']."</td></tr>";
        
    $codenum++;
        }
    }
    echo 
    "</table> 

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2008
    Location
    Plano, TX
    Posts
    115
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I figured it out. it was quite easy I had to add one line of code.

    $code = str_replace(CHR(10), "&nbsp;<BR>", $row['code']) ;

    HERE

    while($row = mysql_fetch_array($results)) {
    $code = str_replace(CHR(10), "&nbsp;<BR>", $row['code']) ;
    if($codenum&#37;2 == 1) {

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just use a <pre> tag.


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
  •