Jump to content

[SOLVED] Line breaks in objects?


tkstock

Recommended Posts

I've created my own shopping cart - stored in session state.

 

Essentially, the cart is an object which contains cartline objects, which contain item objects, etc.

 

Each object has the ability to output details about itself via HTML or plain text (plain text is used in receipt mailings).

 

After the user processes their payment, the receipt is built and then sent in an email.

 

Line breaks put directly into the $message string

$message = "Cart information\n"

come out as line breaks in the email.  Line breaks that are output from the objects

return "Item Description\n"

come out with the slash-n in the email.  I've even tried casting the call

(string) $cart->get_cart_line[1]->get_item_description()

but this doesn't work either.

 

Does anyone have thoughts on why the \n isn't being used as a line break in the email if it's being returned from an object?

 

Thanks for your help!!!

Link to comment
Share on other sites

I just had a thought - could this be an issue because I'm serializing the cart before putting it into session state?

 

$_SESSION["cart_name"] = serialize($localcart);

 

So, for the receipt generator, I'm unserializing the cart

$localcart = unserialize($_SESSION["cart_name"]);

then processing the code to build the receipt into the email...?  Although, the receipt text is build after the cart is unserialized...

Link to comment
Share on other sites

Are you sure your using double quotes around all strings? The \n char is not turned into line feeds unless in double quotes.

 

On a side note, there is no need to serialize an object before placing it into the $_SESSION array. Sessions are automatically serialized / unserialized as required.

Link to comment
Share on other sites

Are you sure your using double quotes around all strings? The \n char is not turned into line feeds unless in double quotes.

You are probably right.  I'll check this when I have access to the code again!!!  Thanks!  I was hoping it was something simple.

 

On a side note, there is no need to serialize an object before placing it into the $_SESSION array. Sessions are automatically serialized / unserialized as required.

Does that mean in effect I'm doing serialize(serialize($cart))?  Is there much additional overhead for this or any reason why I should go through my code and remove the serialize / unserialize calls?

 

If I do this:

$_SESSION["cart_name"] = serialize($localcart);

and subsequently do this:

$localcart = $_SESSION["cart_name"]

would the local cart be OK?  I guess I'm not familiar with exactly what the serialize / unserialize do... :)

 

Thanks for your help!

 

Link to comment
Share on other sites

 

If I do this:

$_SESSION["cart_name"] = serialize($localcart);

and subsequently do this:

$localcart = $_SESSION["cart_name"]

would the local cart be OK?  I guess I'm not familiar with exactly what the serialize / unserialize do... :)

 

Thanks for your help!

 

 

All you need do is...

 

$_SESSION["cart_name"] = $localcart;

and...

$localcart = $_SESSION["cart_name"]

 

There probably is little overhead doing it the way your doing it, but just letting you know its not needed.

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.