the5thace Posted July 15, 2013 Share Posted July 15, 2013 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$query.'?key=' $query is surrounded with ' ' when I try to echo. How do I avoid them? Link to comment https://forums.phpfreaks.com/topic/280172-why-is-the-variable-surrounded-by-when-i-put-it-in-to-a-string/ Share on other sites More sharing options...
AbraCadaver Posted July 15, 2013 Share Posted July 15, 2013 You'll have to show more code, like $query, and the echo, and explain the problem a little better. Link to comment https://forums.phpfreaks.com/topic/280172-why-is-the-variable-surrounded-by-when-i-put-it-in-to-a-string/#findComment-1440786 Share on other sites More sharing options...
the5thace Posted July 15, 2013 Author Share Posted July 15, 2013 <?php if ($_POST['query']) { $query = ("'{$_POST['query']}'"); $uri = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/".$query."?key="; echo $uri; echo (file_get_contents($uri).'horse'); } ?> Link to comment https://forums.phpfreaks.com/topic/280172-why-is-the-variable-surrounded-by-when-i-put-it-in-to-a-string/#findComment-1440787 Share on other sites More sharing options...
the5thace Posted July 15, 2013 Author Share Posted July 15, 2013 Been messing around with both ' ' and " ". Neither let me insert a variable without ' ' surrounding it. Please explain how the context of variable can change this. Link to comment https://forums.phpfreaks.com/topic/280172-why-is-the-variable-surrounded-by-when-i-put-it-in-to-a-string/#findComment-1440788 Share on other sites More sharing options...
AbraCadaver Posted July 15, 2013 Share Posted July 15, 2013 Because you have single quotes here: $query = ("'{$_POST['query']}'"); Whats wrong with just? $query = $_POST['query']; Link to comment https://forums.phpfreaks.com/topic/280172-why-is-the-variable-surrounded-by-when-i-put-it-in-to-a-string/#findComment-1440789 Share on other sites More sharing options...
the5thace Posted July 15, 2013 Author Share Posted July 15, 2013 I more or less copied $query = ("'{$_POST['query']}'"); from Bing api booklet and never thought to question how it could interfere. Thanks for the answer. Link to comment https://forums.phpfreaks.com/topic/280172-why-is-the-variable-surrounded-by-when-i-put-it-in-to-a-string/#findComment-1440790 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.