0

i want to escape special characters being fetched in database and want to replace it with apostrohpe sign, this is how i query database

<div class="row course-boxes">
<?php $count= 0; ?>
<?php 
    $query= mysqli_query($connection, "SELECT * FROM coruses_list WHERE category_id='$category' ");
    while($row=  mysqli_fetch_assoc($query)):
        $count++; 
    ?>
    <div class="col-md-4 col-sm-4 col-xs-12" >
       <h2><?php echo $row['course_name'];?></h2>
       <p style="height: 110px; overflow: hidden;"><?php echo substr($row['course_description'], 0 , 400);?>...</p>
           <a class="btn btn-default" href="course_details.php?course=<?php echo $row['course_id']?>&cat=<?php echo $category ?>">View Details</a>
    </div>
<?php endwhile;?>
</div>

but problem is that i am getting output like this

The course will consist of � type

how do i escape or convert them to another character

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Sikander
  • 2,799
  • 12
  • 48
  • 100
  • 1
    You should take a look here: http://stackoverflow.com/questions/279170/utf-8-all-the-way-through – jeroen May 17 '16 at 08:59
  • Try utf8-decoding the variable: $row['course_description'] like this: **** – Poiz May 17 '16 at 08:59
  • Did you checked the table whether the column stores value with � or you are facing issue only with displaying the value? – Karthikeyani Srijish May 17 '16 at 09:01
  • where ever ther is apostrophe sign it does that ( ‘ ) – Sikander May 17 '16 at 09:02
  • Make sure your web page using utf-8 encoding. Add this code in your header Also your field database should use utf-8 collation. Now in PHP code, try using `htmlentities($row['course_name'], ENT_QUOTES, "UTF-8");` or replace the quote from string using `str_replace('’', '', $row['course_name']);` – Karthikeyani Srijish May 17 '16 at 10:53

0 Answers0