Char Encoding

3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 22, 2019   (RSS)

By Jesus - April 18, 2019

Hello,

I've a page in my website that I need to have using charset=ISO-8859-1 and I also need to insert some text slider I created in CMS Builder here on this page but as I'm using charset=utf-8 for CMSBuilder and other pages in my website, when the page display my CMSB content it shows strange characters with the accents.

Is there a way I can make an adjustment in order to keep that specific page using charset=ISO-8859-1 and at the same time display my CMSB content with no issues?

Thank you for pointing me to the right direction and or your help!

Jesus

Hey Jesus, 

PHP has a UTF-8 decode function that will convert UTF8 content to ISO-8859-1. You can read about it here:

https://www.php.net/manual/en/function.utf8-decode.php

Here is an example of how you would use the function with CMS Builder content:

<?php

  include_once('cmsb/lib/viewer_functions.php');

  // load record from 'test_section'
  list($content, $contentMetaData) = getRecords(array(
    'tableName'   => 'test_section',
    'where'       => "`num` = '1'",
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $content = @$content[0]; // get first record
  if (!$content) { dieWith404("Record not found!"); } // show error message if no record found

  //Set content type header for ISO-8859-1
  header('Content-Type: text/html; charset=ISO-8859-1');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
  <head>
    <title>Test</title>
    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  </head>
  <body>
    <?php
      //Convert the content from UTF-8 to ISO-8859-1. 
      //Note: The content is not HTML Encoded in this example
      echo utf8_decode($content['content']);
    ?>
  </body>
</html>

You can see the function being called on the fourth line from the bottom, on a field called 'content' from a test section I created in my CMS.

Let me know if you've got any questions.

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com