1

When I set variables that include angle brackets (< >) or slashes I keep getting errors like the following (code simplified to focus on error):

Parse error: syntax error, unexpected '>' in D:\hosting\8499439\html\test.php on line 2

<?php
   $xml = “<Request>\n”;
?>

I also run into a lot off issues with "unexpected T_String" errors that appear to be related.

I'm running PHP5 on a GoDaddy Windows Server.

What am I doing wrong? (I get the impression I need to to do something so that special characters can be handled in my PHP).

Thanks in advance.

2
  • 3
    Looks like you're using curly quotes instead of regular ones! Commented Nov 24, 2011 at 18:51
  • What are you using to edit your php files? A standard text editor would NOT be inserting the curly quotes. and are NOT treated as " by PHP. Commented Nov 24, 2011 at 18:57

2 Answers 2

4

Your quotes are curly quotes, not straight quotes, so PHP runs into an error processing them. A string can only be recognized with straight quotes.

Use the following code:

<?php
   $xml = "<Request>\n";
?>

Assuming that you have the same error elsewhere, you can probably do a simple search-and-replace to fix the error: search for one of the curly quotes, replace with a straight quote. Repeat with the other curly quote. Make sure to check for straight quotes that may need to be escaped (for instance, something like "Mary said, "I like this."" would need to be escaped as "Mary said, \"I like this.\"")

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks- very eagle eyes. You nailed it!
0

mc10 is right. Additionally I can say, there are only ""(double) and ''(single) quotes in PHP. I suggest you to read about differences between them. I prefer using single quotes only to keep code clear.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.