4 Replies - 308 Views - Last Post: 26 October 2019 - 08:04 AM Rate Topic: -----

#1 nancybaby101   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-July 19

string quotation issues in php

Posted 14 October 2019 - 09:44 AM

I have a url link below which I want to print out

https://www.googleapis.com/drive/v2/files?q="'<FOLDER_ID>' in parents"

So I have tried something like this but having issue with quotation strings

$folder_id  = 'myid';
echo $url= "https://www.googleapis.com/drive/v2/files?q="'$folder_id' in parents" ";


Is This A Good Question/Topic? 0
  • +

Replies To: string quotation issues in php

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15498
  • View blog
  • Posts: 62,060
  • Joined: 12-June 08

Re: string quotation issues in php

Posted 14 October 2019 - 09:46 AM

What does that give you as a result?
Was This Post Helpful? 0
  • +
  • -

#3 astonecipher   User is offline

  • Senior Systems Engineer
  • member icon

Reputation: 3070
  • View blog
  • Posts: 11,779
  • Joined: 03-December 12

Re: string quotation issues in php

Posted 14 October 2019 - 09:52 AM

$folder_id  = 'myid';
$url= "https://www.googleapis.com/drive/v2/files?q={$folder_id}";
echo $url . " in parents";




You shouldn't be adding quotes inside of the url to begin with. And echoing a variable assignment has not purpose that you should be interested in right now either.
Was This Post Helpful? 1
  • +
  • -

#4 guyfromri   User is offline

  • D.I.C Addict

Reputation: 55
  • View blog
  • Posts: 838
  • Joined: 16-September 09

Re: string quotation issues in php

Posted 26 October 2019 - 06:14 AM

This is the other option if you insist on writing it in one line;

echo $url= "https://www.googleapis.com/drive/v2/files?q=".$folder_id ." in parents";

or as previously mentioned, curly brackets will specify a variable instead of plain text

orrrr if you actually want the apostrophes included in the string for some reason then it would print like this

echo $url= "https://www.googleapis.com/drive/v2/files?q='{$folder_id}' in parents";


There are plenty of options available :)/>

This post has been edited by guyfromri: 26 October 2019 - 06:14 AM

Was This Post Helpful? 0
  • +
  • -

#5 CTphpnwb   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3826
  • View blog
  • Posts: 13,946
  • Joined: 08-August 08

Re: string quotation issues in php

Posted 26 October 2019 - 08:04 AM

String manipulation is easier with built-in functions.
$string = "Other stuff with other {tags}. "; 
/*
 Do other stuff..
*/
$string .= "https://www.googleapis.com/drive/v2/files?q={folder_id} in parents";"

$tags = ['{tags}'=>'TAGS', '{folder_id}'=>'FOLDERID'];
$replace = array_keys($tags);
$with = array_values($tags);
echo str_replace($replace, $with, $string);


In this case however, using http_build_url() would probably be a better solution than playing with the string.

This post has been edited by CTphpnwb: 27 October 2019 - 03:12 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1