-2

I want to print " We can't find an email matching the information you provided. "

But PHP won't let me. Anyone know how to fix this ?

enter image description here

`return Redirect::route('account-forgot-password')

->with('error','We can't find an email matching the information you provided. You may have entered an email that doesn't exactly match our records. Try again ');`
iori
  • 3,236
  • 12
  • 43
  • 78
  • "Can't" or 'Can\'t'. – Mark Shevchenko Jan 09 '15 at 13:41
  • Use double quotes instead of single ones. Not ',but ", or put \ in front of quotes you want to use as quotes. – HerpaMoTeH Jan 09 '15 at 13:41
  • You can either use double quotes or a backslash '\' to escape the quotes – Peter Jan 09 '15 at 13:44
  • 4
    The [PHP manual](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.single) has a bunch of examples and explanations around the 4 different ways of specifying string literals. – Charlie Jan 09 '15 at 13:45
  • 1
    people should generally read much more in the manuals...this is such a basic question that RTFM (with a link to the article) should be an accepted answer :/ – cypherabe Jan 09 '15 at 13:47

6 Answers6

5

Well you could change the single quotes to doublequotes, so like:

with("error","We can't find an email matching the information you provided. You may have entered an email that doesn't exactly match our records. Try again ");
  • What I find amazing is that even for a simple question such as this, many answer by suggesting escaping the quote. +1 because you're the only smart enough to provide the simplest, cleanest and easiest to read solution. – N.B. Jan 09 '15 at 13:43
  • For further details see: http://stackoverflow.com/questions/3446216/what-is-the-difference-between-single-quoted-and-double-quoted-strings-in-php – Robin Valk May 04 '15 at 10:34
4

change the single quotes to doublequotes

->with('error',"We can't find an email matching the information you provided. You may have entered an email that doesn't exactly match our records. Try again ");

or change single quote character with a backslash like ' to \'

->with('error','We can\'t find an email matching the information you provided. You may have entered an email that doesn\'t exactly match our records. Try again ');
Ankur Bhadania
  • 4,123
  • 1
  • 23
  • 38
1

What's happening every time you type a single quote is you're closing out the string and PHP starts reading the following text as code. You can avoid this by using double quotes to contain the entire string:

->with("error","We can't find an email...");

or by "escaping" the single quote character with a backslash

->with('error','We can\'t find an email...');
mr_nobody
  • 89
  • 1
  • 7
0

You have to escape the characters like this:

echo('I don\'t like apples');

Timo Schwarzer
  • 399
  • 4
  • 17
0

you have to use \' like with('error','We can\'t find an email matching the information you provided. You may have entered an email that doesn\'t exactly match our records. Try again ');

Pranav Agrawal
  • 466
  • 6
  • 17
0

You can use PHP HEREDOC syntax, like:

$errorMessage = <<<EOD
Example of string with ' and " :)
spanning multiple lines
using heredoc syntax.
EOD;

then use as variable in your function:

->with('error', $errorMessage);
Anton
  • 1,029
  • 7
  • 19