display special chars in php

Simon Leung
Simon Leung used Ask the Experts™
on
I find that the hyphen saved in mysql field can't be displayed properly from php. Is it related to database definition or on the php ocde ?

Thx


echo
<<<HTML
<div class="container">
  <h2>{$row['title']}</h2>
  <div class="row">
    <div class="col-md-12">
        <img  style='float:left;width:200px; margin-right:30px;' src="{$row['image_path']}" alt="Lights"

                  <b>Synopsis</b> <br/>{$row['description']}<br/>
                  Duration: {$row['runningTime']} <br/>
                  Release at: {$row['releaseDate']}<br/>
                  Movie type: {$row['genre']}
                  
      <div>      
  </div>
</div>
HTML;php01.pngphp02.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
nociSoftware Engineer
Distinguished Expert 2018

Commented:
Is it possible it is a "different" hyphen from a tekst editor using UTF-8..?
it doesn't look like it is a ascii 'dash'  / minus character.
ste5anSenior Developer

Commented:
It's not a hyphen as Noci pointed out.

Your maybe using UTF of some kind, but it can be another code-page based charset also.

BUT
1) As your producing HTML, you need to format your data before pushing it into the HTML. E.g. the dates etc. It's not a good idea to use default/implicit formatting.

2) Your data types are not correct. Running time should be an INT, ReleaseDate a DATE, both not [N]VARCHAR. If the genre is not used for a tag cloud only, then it should exist a genre table and a junction table between your movies and the genres.
Hi,

On your HTML page into the <head>

<head>
<meta charset="UTF-8">
</head>

Open in new window


and make sure you save the page using UTF-8 encoding (it have to select the option in Notepad++ or it is default using Bracket editor)

In DB function I think you already save ok
you can use
SET CHARACTER SET utf8

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial