utf8 in a class

Discussion in 'PHP' started by darkhorn, Sep 3, 2009.

  1. #1
    I have created a class which is a web page temlate.
    All the files are utf-8 encoded.
    When I run the page it writes a unseen question mark at the very beggining of the page.
    Headers does not help.
    What I have to do to remove that question mark?

    Here is the main page:
    <?php
    header ('Content-type: text/html; charset=utf-8');
    require ('template.php');
    $homepage = new Page();
    $homepage -> title="dsf";
    $homepage -> keywords="dsf";
    $homepage -> description="dsf";
    $homepage -> content="dsf";
    
    
    $homepage ->Display();
    ?>
    PHP:
    And here is the class:
    <?php
    class Page
    {
    	public $title;
    	public $keywords;
    	public $description;
    	public $content;
    	public $top_menu = array(bla bla bla);
    	public $left_menu = array(bla bla bla);
    							 
    	public function Display()
    	{
    		$this -> DisplayTypes();
    		$this -> DisplayDescription();
    		$this -> DisplayKeywords();
                    //bla bla bla
    		$this -> DisplayFooter();
    	}
    	
    	public function DisplayTypes()
    	{
    	?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://bla bla bla
    PHP:
    The output in Firefox source view is:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang bla bla bla
    Code (markup):
    In the Notepad++ is (copied from Firefox):
    ?<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang bla bla bla
    Code (markup):
    It is a problem while rendering the page (CSS).
     
    Last edited: Sep 3, 2009
    darkhorn, Sep 3, 2009 IP
  2. shaunole

    shaunole Peon

    Messages:
    24
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can run a hexdump on the html to determine which ascii character it is trying to output. Then you should at least know what character to look for. Usually, these are characters created from Microsoft or similar products as they don't use the typical hyphen, apostrophe or quote characters. I don't see anything unusual in the content you posted.
     
    shaunole, Sep 3, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I don't see anything either, but I'd change one thing in your script..

    You're doing:

    $homepage -> title="dsf";
    PHP:
    Please change this to:

    $homepage->title = "dsf";
    PHP:
    (and the same for the other variables)

    It most likely has nothing to do with your problem, but I thought I'd mention it anyway..
     
    premiumscripts, Sep 3, 2009 IP
  4. darkhorn

    darkhorn Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Okay, thanks for it.

    I found that the problem is related with PHP itself. It does not ignore UTF-8's DOM's (or whaterver they call it) and prints it. PHP6 will have support for UTF-8.

    I think I can solve this problem by moving the variables' values to a database.
     
    darkhorn, Sep 3, 2009 IP
  5. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I would have thought saving your files as UTF-8 without BOM would do the trick. I remember I had an endless problem with this BOM-thing when I first tried to put utf-8 characters in my files, I kept getting 'headers already sent' errors - until i found out i shouldn't have saved with BOM. Then it worked fine.
     
    szalinski, Sep 3, 2009 IP
  6. darkhorn

    darkhorn Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yesterday I tried it and didn't work.
    Now worked. Perhaps Notpad++ is not stable always(?).
     
    darkhorn, Sep 3, 2009 IP