-2

I am attempting to include double quotations in a php variable.

The desired output in this example would be:

  • "John Smith"

Here is my latest, failed attempt...

<?php

if (isset($_POST['firstName']) && isset($_POST['lastName'])) {

  $username = $_POST['firstName'];
  $userpassword = $_POST['lastName'];
  $combined = '- ' . '\”' . $firstName . ' ' . $lastName . '\”';

}

?>
Nam Tab
  • 25
  • 6

1 Answers1

-1

Here is answer to your question https://stackoverflow.com/a/7999163/2585154

And the variable name is misspelled in your code. For your $combined var you are using $firstName and $lastName but there are no such variables.

Try this:

if (isset($_POST['firstName'], $_POST['lastName'])) {
    $firstName = $_POST['firstName'];
    $lastName = $_POST['lastName'];

    $combined = "{$firstName} {$lastName}";

    // John Smith

    // or:

    $combined = "\"{$firstName} {$lastName}\"";

    // "John Smith"
}

P.S. Read this doc PHP: Strings

Dmitry K.
  • 3,065
  • 2
  • 21
  • 32
  • Thanks but that did not work. No double quotes on output. – Nam Tab Dec 23 '22 at 04:17
  • @NamTab Did you try $combined = "\"{$firstName} {$lastName}\""; ? – Dmitry K. Dec 23 '22 at 04:18
  • @NamTab look here - https://onlinephp.io/c/585ff (press the Execute code button) – Dmitry K. Dec 23 '22 at 04:25
  • Thanks Dimitry. I left out one of the double quotes on the right. Works now. Thank you! – Nam Tab Dec 23 '22 at 04:30
  • If I have a similar question how should I post it? As a new question with a similar title, or somehow add it to this question? I don't want to violate the sites rules. – Nam Tab Dec 23 '22 at 18:02
  • @NamTab before posting a new question, you should try to find a similar question on this site because your question may already have been answered. Here is guideline how to ask - https://stackoverflow.com/help/how-to-ask – Dmitry K. Dec 23 '22 at 18:59