Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Inserting html tags into php

    Hi, I have a list of news items that I would like separated by a line break. Whenever I insert a <p> or a <br /> the news items all get surrounded by quotes and seperate the items by more than a line break.

    Here is my php:

    PHP Code:
    while ($article mysql_fetch_array($articles)) {

      
    $id $article['id'];
      
    $articletext $article['LEFT(articletext, 120)'];

      
    // If the article text is 120 characters long, add "..." to the end of it
      // to indicate that it is actually longer. strlen() returns string length!
      
    if (strlen($articletext) == 120) {
        
    $articletext .= "...";
      }

      
    // Remove any custom tags (even partial ones!) in the article text. They are not needed in this preview.
    $articletext ereg_replace('\\[(B|EB|I|EI|L|L=|L=[-_./a-z0-9!&%#?+,\'=:;@~]+|EL|E)?(]|$)''',
    $articletext);

      
    // Finally, make it safe to display in an HTML document
      
    $articletext htmlspecialchars($articletext);

      
    $author htmlspecialchars($article['name']);
      
    $email htmlspecialchars($article['email']);
      
    $adate $article['articledate'];

      echo 
    "<tr valign=\"top\">\n";
      echo 
    "<td><a href=\"article.php?id=$id\">$articletext</a></td>\n";
      echo 
    "<td><a href=\"mailto:$email\">$author</a></td>\n";
      echo 
    "<td>$adate</td>\n";
      echo 
    "</tr>\n";
    }
    ?> 

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    You have a line here that does just that ... it takes out HTML commands.
    That's what it's supposed to do:

    // Finally, make it safe to display in an HTML document
    $articletext = htmlspecialchars($articletext);

    Comment out that line and see what happens ... like this:

    // Finally, make it safe to display in an HTML document
    // $articletext = htmlspecialchars($articletext);

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No difference...with the <p> </p> tags but I got the <br /> tags working.
    Last edited by XiledWeb; 12-23-2006 at 08:09 PM.


  •  

    Posting Permissions

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