Curtis Adams
Curtis Adams

Reputation: 33

PHP "define" and escaped characters

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.

Upvotes: 2

Views: 64

Answers (2)

baao
baao

Reputation: 73241

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);

Upvotes: 0

rm-vanda
rm-vanda

Reputation: 3158

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.

Upvotes: 1

Related Questions