Horde_Mime_Part::replaceEOL PHP Method

replaceEOL() public method

Replace newlines in this part's contents with those specified by either the given newline sequence or the part's current EOL setting.
public replaceEOL ( mixed $text, string $eol = null, boolean $stream = false ) : string
$text mixed The text to replace. Either a string or a stream resource. If a stream, and returning a string, will close the stream when done.
$eol string The EOL sequence to use. If not present, uses the part's current EOL setting.
$stream boolean If true, returns a stream resource.
return string The text with the newlines replaced by the desired newline sequence (returned as a stream resource if $stream is true).
    public function replaceEOL($text, $eol = null, $stream = false)
    {
        if (is_null($eol)) {
            $eol = $this->getEOL();
        }
        stream_filter_register('horde_eol', 'Horde_Stream_Filter_Eol');
        $fp = $this->_writeStream($text, array('filter' => array('horde_eol' => array('eol' => $eol))));
        return $stream ? $fp : $this->_readStream($fp, true);
    }

Usage Example

Example #1
0
 $textpart->setType('text/plain');
 $textpart->setCharset('UTF-8');
 $textpart->setContents(_("You have been sent an Ecard. To view the Ecard, you must be able to view text/html messages in your mail reader. If you are viewing this message, then most likely your mail reader does not support viewing text/html messages."));
 /* Create the multipart/related part. */
 $related = new Horde_Mime_Part();
 $related->setType('multipart/related');
 /* Create the HTML part. */
 $htmlpart = new Horde_Mime_Part();
 $htmlpart->setType('text/html');
 $htmlpart->setCharset('UTF-8');
 /* The image part */
 $imgpart = new Horde_Mime_Part();
 $imgpart->setType($image->getType('screen'));
 $imgpart->setContents($image->raw('screen'));
 $img_tag = '<img src="cid:' . $imgpart->setContentID() . '" /><p />';
 $comments = $htmlpart->replaceEOL(Horde_Util::getFormData('ecard_comments'));
 if (!Horde_Util::getFormData('rtemode')) {
     $comments = '<pre>' . htmlspecialchars($comments, ENT_COMPAT, 'UTF-8') . '</pre>';
 }
 $htmlpart->setContents('<html>' . $img_tag . $comments . '</html>');
 $related->setContentTypeParameter('start', $htmlpart->setContentID());
 $related->addPart($htmlpart);
 $related->addPart($imgpart);
 /* Create the multipart/alternative part. */
 $alternative = new Horde_Mime_Part();
 $alternative->setType('multipart/alternative');
 $alternative->addPart($textpart);
 $alternative->addPart($related);
 /* Add them to the mail message */
 $alt = new Horde_Mime_Mail(array('Subject' => _("Ecard - ") . Horde_Util::getFormData('image_desc'), 'To' => $to, 'From' => $from));
 $alt->setBasePart($alternative);
All Usage Examples Of Horde_Mime_Part::replaceEOL