Jump to content

[SOLVED] create a string that includes the "\"


thewooleymammoth

Recommended Posts

Either...

<?php

  $str = "this is s string with a \\ backslash in it.";

  // or

  $str = 'this is s string with a \ backslash in it.';

?>

 

yes but i want the string to only contain "\" and when the backslash is placed next to a quote doesnt it automatically ignore the end quote?

ok, using a slash in a string enclosed in quotes - cancels out the next character. So basically to have it echo \ literally, you will have to cancel out the slash to be taken literally with a preceeding slash.

 

example:

echo "\n"; //returns a newline character

echo "\\n"; //returns \n

 

So if you want it to echo a \:

echo "\\"; //returns \

 

If you literally want "\":

echo "\"\\\""; //returns "\"

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.