Jump to content

question regarding adding onto a variable that contains text ...


Jax2

Recommended Posts

Perhaps I misunderstood, but I thought that if you declared a variable, you could add onto it later in the script... such as something like this:

 

$body="This is the first line of the text.\r\n";
$body .="This will be inserted below the first line. Therefore it's the second.\r\n";
$body .="This will be considered the 3rd line.";

 

Which I thought would produce:

$body="This is the first line of the text.\r\n

This will be inserted below the first line. Therefore it's the second.\r\n

This will be considered the 3rd line."

 

Am I mistaken here? I have a script that has to perform a couple of while loops in order to insert array data into the body of an email I'm sending, yet when I did it like this, $body was blank.

 

Any suggestions?

 

 

Link to comment
Share on other sites

There's nothing wrong with what you are doing (test it in a file by itself.)

 

If you are getting an empty variable later in your code, either your code is clearing the variable or the variable is not available due to it being in a different scope. You would need to pin down where in your code the variable has the expected content and where it does not.

 

If you want us to help determine where in your code that is occurring, you will need to post your code.

Link to comment
Share on other sites

I did what was suggested and tried it out in a simple test.php script and yes, it worked perfectly. I had been rechecking my code for a good hour before I decided to ask the question because nothing was coming up correctly.

 

Dun dun duuuuun..... I had spelled recipeID as recpieID and it couldn't find the recipe in question so it returned nothing.

 

(slaps self on forehead).

 

You'd think I'd have started by echoing back the variables at the top of the page to make sure they were being passed correctly, wouldn't you?  :wtf:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.