0

I am trying to get the HTML template from the GMAIL original email view, the problem is that gmail adds an = character to the end of each line.

I used a foreach loop to iterate through the lines and remove the "=" character, but it is still not working at all.

I also have an if statement to validate the existence of the character.

Example GMAIL original view lines:

    body[dir=3Drtl] .directional_text_wrapper { direction: rtl; unicode-bid=
i: embed; }

  </style>
</head>
<body lang=3D"en-us" style=3D"width:100%!important;margin:0;padding:0">
  <div style=3D"padding:10px;line-height:18px;font-family:&#39;Lucida Grand=
e&#39;,Verdana,Arial,sans-serif;font-size:12px;color:#444444">

Code:

<?php

$original_email=file("original.html");
foreach ($original_email as   $line) 
 {
    $sbstr=substr($line,-2,1);
    if( $sbstr == "="){
        echo $substr;
    }

 }


?>

UPDATE

I have tried using the rtrim() function with no luck.

The updated code:

<?php

    $original_email=file("original.html");
    foreach ($original_email as   $line) 
     {
        /*
        $sbstr=substr($line,-2,1);
        if( $sbstr == "="){
            echo $substr;
        }
        */
        rtrim($line,"=");

     }


    ?>
nomorehere
  • 332
  • 2
  • 12
  • 1
    Maybe you need `quoted_printable_decode`, see http://stackoverflow.com/questions/9860243/remove-n-from-html – aghidini Sep 03 '16 at 18:46

4 Answers4

1

You can use the PHP function rtrim

rtrim — Strip whitespace (or other characters) from the end of a string

Use the following syntax to remove = at the end of the line

$line = rtrim($line, "=");
Daniel
  • 10,641
  • 12
  • 47
  • 85
1

using rtim function

rtrim ( $sbstr,"=")
odai
  • 190
  • 1
  • 5
  • 19
1

Try to trim your string first for whitespace using trim and then rtrim the '=' character.

$line = trim($line);
$line = rtrim($line,'=');
Neil Yoga Crypto
  • 615
  • 5
  • 16
0

I have removed the "3D" added in each line, and made a loop that cuts the end of the line and checks if it's equal to "=" or not, if yes, it deleted it using substr.

<?php

$original_email=file("original.html");
foreach ($original_email as   $line) 
 {
$line=str_replace("3D","",$line);
if($sbstr=substr($line,-2,1) == "=")
{
$ln=substr($line,0,strlen($line)-2);
    echo htmlentities($ln)."<br>";
}
}


?>
nomorehere
  • 332
  • 2
  • 12
  • While this may answer the question, posting code-only answers is discouraged. It's best to explain what the problem was, and what you have done to solve it. – miken32 Sep 03 '16 at 23:30
  • I have edited it just now, to clarify what i've exactly done. – nomorehere Jul 19 '17 at 01:27