声明变量php [重复]时出错

This question already has an answer here:

I want to Declaring variable

and I get error

Parse error: syntax error, unexpected 'book' (T_STRING)

mycode

$filters = "library&loc=local,scope:("book")&loc=local,scope:("book2")....";
$path = "http://xxxxx/place/search/institution=".$filters."";

in line $filters=..... is error

and I don't want to change "..." to '...' because my result is change

</div>

You need to escape the double quotes:

$filters = "library&loc=local,scope:(\"book\")&loc=local,scope:(\"book2\")....";

Alternatively, you can use single quotes for the entire string:

$filters = 'library&loc=local,scope:("book")&loc=local,scope:("book2")....';

Both of these result in the same string which is library&loc=local,scope:("book")&loc=local,scope:("book2")....

You are using double quotes in the variable wich caused the error. You need to escape these quotes for example:

scope:(\"book\")

Or use single quotes:

scope:('book')

Same for book2.

I hope this will help!

@ARR.s use \before " like \" try below one:

<?php
$filters = "library&loc=local,scope:(\"book\")&loc=local,scope:(\"book2\")....";
$path = "http://xxxxx/place/search/institution=".$filters."";

This should fix it. Use single quotes at the start and end of your string:

$filters = 'library&loc=local,scope:("book")&loc=local,scope:("book2")....';

You're using wrong the double quotes:

$filters = "library&loc=local,scope:("book")&loc=local,scope:("book2")....";

If you want to use double quotes inside a string declared using double quotes you have to scape them:

$filters = "library&loc=local,scope:(\"book\")&loc=local,scope:(\"book2\")....";

Anyway, the difference between using double and single quotes in php is that double quotes are evaluated, in your case you're not evaluating anything, so you can do this (and is a little faster becouse php doesn't have to evaluate the string)

$filters = 'library&loc=local,scope:("book")&loc=local,scope:("book2")....';

I recommend you to read the php strings documentation to understand the difference between double quoted and single quoted strings and how string evaluation works