Snapcaster
Snapcaster

Reputation: 159

PHP string skips to next line after inserted variable?

I'm using the php mail function and trying to insert variables into my email messages. Here is some sample code that's similar to what I'm doing

<?php
$name = "franklin";
$message = "blah blah blah".$name.".";
?>

$name is coming from a csv file.

The problem is that the period after $name is being bumped to the next line, so the message looks like this:

blah blah blah franklin
.  <--period is here

Is there any way to stop this from happening?

Upvotes: 2

Views: 178

Answers (2)

Roman
Roman

Reputation: 3833

try this:

str_replace("\n", "", $name);

or

trim($name);

Upvotes: 3

anubhava
anubhava

Reputation: 784898

Try trim function like this:

$message = "blah blah blah". trim($name) . ".";

Your variable $name might have EOL as the last character thus bumping period after that to next line.

Upvotes: 3

Related Questions