0

Hello I'm trying to echo some text that I put into mysql that contains apostrophes. However whenever I try to echo the text out the apostrophes are replaced with boxes.

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT * FROM rules";
$result = mysqli_query($link, $query);

while($row =  $result->fetch_array()) {
    echo '<article class="content grid_10 push_1">';

    echo '<h1>';
    echo $row['title'];
    echo '</h1>';

    echo '<section>';

    echo nl2br(stripslashes($row['post']));

    echo '</section>';
    echo '</article>';

}?> 

1 Answers1

0

Try this (encoding with utf-8):

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$query = "SELECT * FROM rules";
$result = mysqli_query($link, $query);

while($row =  $result->fetch_array()) {
    echo '<article class="content grid_10 push_1">';

    echo '<h1>';
    echo utf8_encode($row['title']);
    echo '</h1>';

    echo '<section>';

    echo nl2br(stripslashes(utf8_encode($row['post'])));

    echo '</section>';
    echo '</article>';

}?> 
Adrian B
  • 1,490
  • 1
  • 19
  • 31