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,"=");

     }


    ?>
1

4 Answers 4

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, "=");
Sign up to request clarification or add additional context in comments.

1 Comment

Still not doing anything
1

using rtim function

rtrim ( $sbstr,"=")

3 Comments

Still not doing anything
use str_replace("=","",$line); if you want to remove ALL the '=' char
No , some "=" are needed like in ' style= '
1

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

$line = trim($line);
$line = rtrim($line,'=');

Comments

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>";
}
}


?>

2 Comments

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.
I have edited it just now, to clarify what i've exactly done.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.