1

I'm new to php and I need to assign these two strings to variables and echo them exactly as seen below:

String 1:

<div class='annoying_string' id="garbage">Programming & PHP rules \\ must try</div>

String 2:

(?:(?:\r\n)?"[ \t]")*(?:(?:(?:'[^()<>@,;:\\".\'[\]' \000-\031]+(?:(?:(?:\r\n)?[ \t]

I apologize in advance as I'm sure this question's aspects have all been answered multiple times - I did see quite a number of related articles, and I read about escaping with backslashes and stuff but in this string there are "s, 's, \s, practically everything and I fail to see how I can 'escape' all of them...

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Randomdude
  • 101
  • 2
  • 9

1 Answers1

1

Instead of messing around with escaping, it may be much simpler to use a nowdoc:

$string1 = <<<'EOD'
<div class='annoying_string' id="garbage">Programming & PHP rules \\ must try</div>
EOD;

$string2 = <<<'EOD'
(?:(?:\r\n)?"[ \t]")*(?:(?:(?:'[^()<>@,;:\\".\'[\]' \000-\031]+(?:(?:(?:\r\n)?[ \t]
EOD;
Mureinik
  • 297,002
  • 52
  • 306
  • 350