Using “n” properly for echo statement

We are using Woocommerce for our ecommerce platform and we have encountered a problem with the order emails where sometimes the link is too long and it breaks when a customer tries to click the link to start their digital download.

I did some research and found out you could counter this problem by placing “n” within the link section of the order emails.

Read More

While doing a test it looks like it worked but it is actually printing the n before the text of my link.

So for example this is how I have it in the template file:

echo ' <a href="' . $download_file_url . '" target="_blank">n' . $filename . '</a></small>';

But this is how it looks on the customer email: Download 1: nMy-Customer-Download.m4v

Am I using it properly?

The reason I need to do that is because if the links are too big for some of the downloads then some mail clients will insert a %20 randomly in some of the links, I guess to break it up for display in the email. So after researching some solutions I saw some people were able to correct this by using the “n” within the content of the email to break it up.

Related posts

Leave a Reply

1 comment

  1. Variables/escaped characters do not expand in single quotes.

    If you want to use a n character you have to use double quotes:

    echo 'No newnline';
    echo "Yes newnline";
    

    Output:

    No newnlineYes new
    line

    DEMO

    Alternatively, you can always use

    echo 'Single quote string with' . "n" . ' newline!';
    

    or use PHP_EOL:

    echo 'Single quote string with' . PHP_EOL . ' newline!';