• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

Html code from php problem

I got problem to get proper html -code output when i send it to php variable. That php-file send that html-code (including a table) to email and there is problems like some text in the table got "! " characters and above the table there is extra text line. Also every columns are not centered as they are in original html-code.

Original html is correct and tested with browser without any problems.

Problem is with this line (below) in php, i think , but i can't fix it. Can anyone help me?

$email_text = iconv("UTF-8", "ISO-8859-1", stripcslashes($email_text));

Mircci
0
Mircci
Asked:
Mircci
  • 4
  • 3
  • 2
  • +1
3 Solutions
 
bigeven2002Commented:
Hello,

Can you provide the value for $email_text?  I would like to see the problem for myself.
0
 
Ray PaseurCommented:
To second what bigeven2002 said, please post the value of $email_text before and after the line of code that mungs the data string.

Also, please explain why you are using the iconv() function.  What do you expect it to do?
http://php.net/manual/en/book.iconv.php
0
 
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
i guess there is a HTML code in $email_text right? And is this content pulled from a db field.

Now there are some things you need to check.

if your endpage encoding is ISO-8859-1 and your db charset and collations are set to UTF8

$email_text = iconv("UTF-8", "ISO-8859-1", stripcslashes($email_text));

would create proper convertion. Bus i think it's not .

- first check db charset and collations , if you can set them to utf8 (_general)
- second set your endpage charset to utf8
- third be sure there is no BOM usage for your files (open your files with notepad++ and save files after changing encoding -encoding/convert to utf without bom)
- lastly check if you have right content in db fields
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
MircciAuthor Commented:
to bigiven:
Test.html file include html-code that gives me trouble.

to Ray_Paseur:
Without iconv() function i can't get scandinavian characters (äöå) right.

to erdincgc:
Actually that html-code generated from my AIR application not from database.
test.html
0
 
Ray PaseurCommented:
That is an awful lot of stuff to go through.  Could you please isolate a smaller example for us?  Just a one or two line example showing the before and after issues would be very helpful.

See if this gives you any ideas.

<?php // RAY_entitize_western_letters.php
error_reporting(E_ALL);
echo "<pre>";



// DEMONSTRATE HOW TO TRANSLATE SOME WESTERN CHARACTERS INTO ENGLISH-PRINTABLE OR ENTITIES
// SEE http://www.joelonsoftware.com/articles/Unicode.html


// TEST CASES
$arr
= array
( 'Françoise'
, 'Å-Ring'
, 'ßeta or Beta?'
, 'Öh löök, umlauts!'
, 'ENCYCLOPÆDIA'
, 'ça va! mon élève mi niña?'
, 'A stealthy ƒart'
, 'Jean "Ðango" Reinhardt of Pont-à-Celles'
)
;


// DISPLAY EACH TEST CASE USING ENTITIZED CHARACTERS
echo PHP_EOL . 'USE "VIEW SOURCE" TO LOOK AT THESE';
foreach ($arr as $str)
{
    echo PHP_EOL
    . $str
    . ' = '
    . '<strong>'
    . mungstring($str, 'ENT')
    . '</strong>'
    ;
}


// DISPLAY EACH TEST CASE USING TEXT TRANSLATIONS
echo PHP_EOL;
foreach ($arr as $str)
{
    echo PHP_EOL
    . $str
    . ' = '
    . '<strong>'
    . mungstring($str)
    . '</strong>'
    ;
}


// EXAMPLE SHOWING HOW TO TURN A PORTUGESE NAME INTO PART OF A URL STRING
echo PHP_EOL;
$str = 'Armação de Pêra';
$new = mungString($str);
$new = strtolower($new);
$new = str_replace(' ', '-', $new);

// SHOW THE URL STRING
echo PHP_EOL
. '<strong>'
. '<a target="blank" href="http://lmgtfy.com?q='
. htmlentities(mungstring($new))
. '">'
. $str
. '</a>'
. '</strong>'
;


// EXAMPLE SHOWING HOW TO TURN A STRING INTO A NUMERICALLY ENTITIZED STRING
echo PHP_EOL;
$str = 'Armação de Pêra';
$new = mungString($str, 'ENTITIES');
echo PHP_EOL
. $new
. ' = '
. '<strong>'
. htmlentities($new)
. '</strong>'
;


// EXAMPLE SHOWING ALL THE ORIINAL LETTERS
echo PHP_EOL;
print_r( mungstring(NULL, NULL) );


// A FUNCTION TO RETURN THE WESTERNIZED/ENTITIZED STRING
function mungString($str, $return='TEXT')
{
    // OUR REPLACEMENT ARRAY OF ENTITIES
    static
    $entity
    = array();

    // OUR REPLACEMENT ARRAY OF CHARACTERS (YOU MAY WANT SOME CHANGES HERE)
    static
    $normal
    = array
    ( 'ƒ' => 'f'  // http://en.wikipedia.org/wiki/%C6%91 florin
    , 'Š' => 'S'  // http://en.wikipedia.org/wiki/%C5%A0 S-caron (voiceless postalveolar fricative)
    , 'š' => 's'  // http://en.wikipedia.org/wiki/%C5%A0 s-caron
    , 'Ð' => 'Dj' // http://en.wikipedia.org/wiki/Eth (voiced dental fricative)
    , 'Ž' => 'Z'  // http://en.wikipedia.org/wiki/%C5%BD Z-caron (voiced postalveolar fricative)
    , 'ž' => 'z'  // http://en.wikipedia.org/wiki/%C5%BD z-caron
    , 'À' => 'A'
    , 'Á' => 'A'
    , 'Â' => 'A'
    , 'Ã' => 'A'
    , 'Ä' => 'A'
    , 'Å' => 'A'
    , 'Æ' => 'E'
    , 'Ç' => 'C'
    , 'È' => 'E'
    , 'É' => 'E'
    , 'Ê' => 'E'
    , 'Ë' => 'E'
    , 'Ì' => 'I'
    , 'Í' => 'I'
    , 'Î' => 'I'
    , 'Ï' => 'I'
    , 'Ñ' => 'N'
    , 'Ò' => 'O'
    , 'Ó' => 'O'
    , 'Ô' => 'O'
    , 'Õ' => 'O'
    , 'Ö' => 'O'
    , 'Ø' => 'O'
    , 'Ù' => 'U'
    , 'Ú' => 'U'
    , 'Û' => 'U'
    , 'Ü' => 'U'
    , 'Ý' => 'Y'
    , 'Þ' => 'B'
    , 'ß' => 'Ss'
    , 'à' => 'a'
    , 'á' => 'a'
    , 'â' => 'a'
    , 'ã' => 'a'
    , 'ä' => 'a'
    , 'å' => 'a'
    , 'æ' => 'e'
    , 'ç' => 'c'
    , 'è' => 'e'
    , 'é' => 'e'
    , 'ê' => 'e'
    , 'ë' => 'e'
    , 'ì' => 'i'
    , 'í' => 'i'
    , 'î' => 'i'
    , 'ï' => 'i'
    , 'ð' => 'o'
    , 'ñ' => 'n'
    , 'ò' => 'o'
    , 'ó' => 'o'
    , 'ô' => 'o'
    , 'õ' => 'o'
    , 'ö' => 'o'
    , 'ø' => 'o'
    , 'ù' => 'u'
    , 'ú' => 'u'
    , 'û' => 'u'
    , 'ý' => 'y'
    , 'ý' => 'y'
    , 'þ' => 'b'
    , 'ÿ' => 'y'
    )
    ;

    // RETURN THE "TRANSLATED" TEXT
    if (substr(strtoupper($return),0,1) == 'T') return strtr($str, $normal);

    // RETURN THE "ENTITIZED" TEXT
    if (substr(strtoupper($return),0,1) == 'E')
    {
        if (empty($entity))
        {
            foreach ($normal as $key => $nothing)
            {
                $entity[$key] = '&#' . ord($key) . ';';
            }
        }
        return strtr($str, $entity);
    }

    // MIGHT BE USEFUL TO GET THE LIST OF ORIGINAL LETTERS
    return array_keys($normal);
}

Open in new window

0
 
Erdinç Güngör ÇorbacıPHP Development Team LeaderCommented:
hmm you do you read that file with fopen or get with filegetcontents or any other option ?

first of all the php page you do these works must be in the right text format. would you please open your main php file with notepad++ and look at the endoding type.

then check your email headers, try by using these

$from="sender@emailaddress.com";
$separator = md5(time());
$eol = PHP_EOL;
$headers  = "From: ".$from.$eol;
$headers .= "Reply-To: $from \n";
$headers .= "MIME-Version: 1.0".$eol; 
$headers .= "Content-Type: text/html; charset=\"ISO-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;

Open in new window


and another thing that i saw ; Your html file's headers are not defined.

this is the whole head of html
<html><head><title>Auditointi</title></head>

Open in new window


try adding at least content encoding to html and you may need to change your air app according to this if this solves.

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Open in new window

0
 
MircciAuthor Commented:
to erdincgc:
That html-code is sended to php variable not readed from file ( $email_text=$_POST['my_text'];). Encoding type is UTF-8 in php-file. I tested that header and meta tag, no help.

to Ray_Paseur:
Sorry but this exact example gives me trouble, not any html-text what i generate, some emails are correct. I tested your php with my html-code and it not helped. When i print that html to the screen it is correct but in email there is errors like some </strong> tags is showing in the text and all columns are not centered.
0
 
Ray PaseurCommented:
Let's get back to the original request from the EE community.  Please post your test data sample showing the before and after effect of the transition that your program causes.

Then post the program code you are using now.

Then post the "after" version of the test data that you want to achieve, so we can see the differences.

Without this information, it's just a guessing game.  Thanks, ~Ray
0
 
MircciAuthor Commented:
Okay, my problem is solved. That html-code needed <tbody></tbody> tags inside <table></table> tags. It shows correctly with any browser etc. without those tags but when it sended to email it needs "tbody" tags to show correctly.

Thanks everyone anyway!
0
 
Ray PaseurCommented:
Had you posted the test data sample, like we asked, you might have gotten an answer a lot sooner.  This question went up on the 12th of this month.  It should have been solved in a matter of minutes, and it could have been if you had shown us a managably sized data sample.  

Please read the grading guidelines and explain the grade, thanks.
http://www.experts-exchange.com/help/viewHelpPage.jsp?helpPageID=26
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now