Search code examples
phphtml-entitiesnl2br

Some text to be bold after every line break after using nl2br


I am fetching data from one field called PostContent from mysql DB and using nl2br which comes as line break. i have succeeded to fetch the nl2br but i want some text to be bold after every line break.

in Database i have stored as longtext for postContent i want output as follows:

Dimensions:

Height: 134.7 mm
Width: 68.5 mm

Display and User Interface:

Display size: 11.94 cm

Keys and Input Methods:

some text
some more text

i am geting like:

Dimensions:
Height: 134.7 mm
Width: 68.5 mm

Display and User Interface:
Display size: 11.94 cm

Key Features: Should be Bold</B>
some text
some text

the code is:

$url=$_GET['url'];
$sql ="SELECT * , DATE_FORMAT( postDate,  '%d %b %Y' ) postDate FROM posts where url ='$url'";
mysql_query("SET NAMES utf8");
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$postContent=nl2br($row['postContent']);
?>
                <div class="col-md-12">
                    <p><?php echo"$postContent.";?></p>
                </div>
<?php
}
mysql_free_result($result);
mysql_close();
?>

Solution

  • I thank everyone for their kind support. i got solution for my question so thought of sharing the same, With the help of tinymce and html_entity_decode now i am able to get the desired output. actually i am inserting the html tags in database with the help of HTML WYSIWYG called tinymce and rendeting the same using html_entity_decode. now using following code i can insert any html tag and render the same using html_entity_decode without rendering the html tags.

    $url=$_GET['url'];
    $sql ="SELECT * , DATE_FORMAT( postDate,  '%d %b %Y' ) postDate FROM posts where url ='$url'";
    mysql_query("SET NAMES utf8");
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
    {
    $postContent=nl2br($row['postContent']);
    $content=html_entity_decode($postContent);
    ?>
                    <div class="col-md-12">
                        <p><?php echo"$content.";?></p>
                    </div>
    <?php
    }
    mysql_free_result($result);
    mysql_close();
    ?>