2

Is there a way to insert an escaped character for carriage return in a define() statement?

define('MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT', 
       "WSW uses PayPal as its primary merchant card account vendor./r
        You can check out with PayPal without the use of a PayPal account.");

I attempted the above statement but it will only out put the /r as literal.

Cœur
  • 37,241
  • 25
  • 195
  • 267

2 Answers2

1

You have to use double quotes around the defined string - but use "\n" instead -- The "\n" and "\r" really only work when you are using the script via php-cli or some equivalent.

If you are rendering this in/echoing to HTML, you'll have to use <br>

But, while you're at it, if you inspect the source via Ctrl+U or view-source: - then you'll see that your "\n" (I think "\r" may be the legacy version) - does, in fact appear as a line break.

Example:

echo "The quick brown fox <br> jumped over the lazy dog"; 
echo "The quick brown fox \n jumped over the lazy dog";

Try running that, and it'll make sense.

rm-vanda
  • 3,122
  • 3
  • 23
  • 34
  • However, on inspecting the source the break is there and it is shown as a new line in the source but that is not being reflected on the actual page. – Curtis Adams Nov 12 '14 at 01:47
  • Exactly -!- You see, in the answer you accepted, the guy used `nl2br` which literally translates the `\n` to a `
    ` -- because in HTML, it will not break the line unless you tell it to... for the same reason that if you have a

    tag, press enter a bunch of times, the browser still renders it all on the same line.

    – rm-vanda Nov 12 '14 at 15:45
0

You need to change /r to \r (or \n - why see here)

If you want to echo it, you can simply use nl2br function:

echo nl2br(MODULE_PAYMENT_PAYPALWPP_MARK_BUTTON_TXT);
Community
  • 1
  • 1
baao
  • 71,625
  • 17
  • 143
  • 203