Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Clearing HTML using PHP

Featured Replies

I'm currently developing a blog and on the homepage I have it so that it pulls in extracts from each post so that the reader must visit the post page. I've got it so that it displays the extract but for some reason it also displays the HTML tags for example if I put <br> in the text it doesn't just add the break. It also displays the tag. Check out the image below to see what I mean. Any help with this problem is seriously appreciated.

24zlvz9.png

 

I did find a certain tool called HTML Purifier but I'm unsure how I am to implement it.

 

Here's my homepage code currently:

<html>
   <head>
       <title>Ultan Casey | Web Designer, Technology Entusiast, Music Lover!</title>
       <link rel="stylesheet" href="css/style.css" type="text/css" />
   </head>
   <body>
        <div class="wrapper">
            <div id="upperbar">
            <a href="#">Home</a>
            <a href="#">About Me</a>
            <a href="#">Contact Me</a>
            <a href="http://www.twitter.com/UltanKC">Twitter</a>
        <form id="search-form" action="/search" method="get">
            <input type="text" id="textarea" size="33" name="q" value=""/>
            <input type="submit" id="submit" value="Search"/>
        </form>
            </div>
            <div id="banner">
            <img src="images/banner.jpg">
            </div>
            <div class="sidebar"></div>
            <div class="posts">
            <?php
            mysql_connect ('localhost', 'root', 'root') ;
            mysql_select_db ('tmlblog');

            $sql = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 5";

            $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']);
                $id = $row['id'];

                ?>
                 <?php echo "<p id='title'><strong><a href=\"post.php?id=". $id . "\">" . $title . "</a></strong></p>"; ?><br />

                       <div class="post-thumb"><img src="thumbs/<?php echo $id ?>.png"></div>
                       <?php echo nl2br(htmlspecialchars(substr($entry, 0, 1050))) ?>... 	 
                       <br>          

                       <hr><br />
                       Posted on <?php echo $date; ?>
                       </p>
                       </div>

                                   </div>


                           </p 


                           <?php
                       }
                       ?>
                      </div> 
            </div>

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

  • Author

Change

<?php echo nl2br(htmlspecialchars(substr($entry, 0, 1050))) ?>

to

<?php echo nl2br(substr($entry, 0, 1050)) ?>

 

I have to say that you are just awesome! Thanks for the help! :drinks:

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.