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? Quote 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. Quote 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'); } ?> Quote 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. Quote 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...
Solution AbraCadaver Posted July 15, 2013 Solution Share Posted July 15, 2013 Because you have single quotes here: $query = ("'{$_POST['query']}'"); Whats wrong with just? $query = $_POST['query']; Quote 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 (edited) 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. Edited July 15, 2013 by the5thace Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.