How to render special character in HTML page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dagam3rz
    New Member
    • Jul 2010
    • 11

    #1

    How to render special character in HTML page

    Guys I'm having so much difficulty in rendering special character to my html page. The character listed below are some of the chars I'm trying to render. I'm retrieving the character from mysql database using PHP the to HTML. I've enclosed the chars in single quote.

    '´' 'Ñ' 'ñ' 'é' 'è' 'ë' 'ö' '“' '”' '’' '—' '–' '™' '§'

    Please help me.

    Thanks a lot.
  • JKing
    Recognized Expert Top Contributor
    • Jun 2007
    • 1206

    #2
    Hi there.
    I think what you are looking for is htmlentities().

    Have a look at this link: PHP htmlentities

    Comment

    • dagam3rz
      New Member
      • Jul 2010
      • 11

      #3
      Have tried it htmlentities() already but it doen't work.
      Locally on my machine I was able to resolve it.
      I used the code below.

      Code:
      function specialCharsToHtml($str){
      $match_pattern =       array('´', 'Ñ', 'ñ', 'é', 'è', 'ë',
      'ö', '“', '”', '’', '—', '–', '™', '§',
      'á');
      $replacement_pattern = array(''','Ñ','ñ', 'é', 'è', 'ë',
      'ö', '“', '”', '’', '—', '–', '™', '§',
      'á');
      return str_replace($match_pattern, $replacement_pattern, $str);
      }
      When I uploaded it to my site, it doesnt work.
      Last edited by dagam3rz; Jul 9 '10, 08:15 PM. Reason: To change replacement pattern

      Comment

      • JKing
        Recognized Expert Top Contributor
        • Jun 2007
        • 1206

        #4
        Originally posted by dagam3rz
        Have tried it htmlentities() already but it doen't work.
        Locally on my machine I was able to resolve it.
        I used the code below.

        Code:
        function specialCharsToHtml($str){
        $match_pattern =       array('´', 'Ñ', 'ñ', 'é', 'è', 'ë',
        'ö', '“', '”', '’', '—', '–', '™', '§',
        'á');
        $replacement_pattern = array(''','Ñ','ñ', 'é', 'è', 'ë',
        'ö', '“', '”', '’', '—', '–', '™', '§',
        'á');
        return str_replace($match_pattern, $replacement_pattern, $str);
        }
        When I uploaded it to my site, it doesnt work.
        Code:
        <?php
        $str = "´ Ñ ñ é è ë ö “ ” ’ — – ™ §";
        
        echo htmlentities($str, ENT_QUOTES, 'cp1252');
        ?>
        That properly translates all characters to their html entities for me.

        Comment

        Working...