1

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

ARR.s
  • 769
  • 4
  • 20
  • 39
  • 1
    Look at the highlighting. You'll need to escape the quotes if you don't want to change to singlequotes, making it `...scope:(\"book\")&...` – Qirel Mar 08 '17 at 14:20

5 Answers5

3

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")....

Jonathon
  • 15,873
  • 11
  • 73
  • 92
1

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!

node_modules
  • 4,790
  • 6
  • 21
  • 37
1

@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."";
lazyCoder
  • 2,544
  • 3
  • 22
  • 41
1

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")....';
Ramy Talal
  • 71
  • 8
1

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

lcjury
  • 1,158
  • 1
  • 14
  • 26