/    Sign up×
Community /Pin to ProfileBookmark

PHP: file_get_contents turn & to &amp

After searching alot and followed most of the posts, i still couldn’t resolve my problem.

Problem: file_get_contents turn & to &amp.

This is my code:

<?php

include ‘paths.php’;

session_start();
echo file_get_contents($solr_path.’select?q=’.urlencode($_SESSION[‘super’]).’&df=dict_word&wt=json&indent=true’);
?>

I checked the url, its working when i change &amp with &. I’ve tried urlencode, htmlspecialchars_decode() and http_build_query() but nothing seems to work.

I than used curl but still i can’t get the data from url on my system.

<?php
session_start();
$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $solr_path.’select?q=’.urlencode($_SESSION[‘super’]).’&df=dict_word&wt=json&indent=true’);
curl_exec ($curl);
curl_close ($curl);
?>

Than i run the code on another system webserver, both get_file_content and curl is working, giving me the data from the url. What could be the problem in my system? Both system php versions are 5.4.16.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 20.2016 — Can you explain a bit more what you mean by "file_get_contents() turns '&' into '&amp'"? Are you saying it's doing that to everything in the query string you are providing to it, or that something in $_SESSION['super'] has an '&' in it that is being converted incorrectly, or something else?
Copy linkTweet thisAlerts:
@ginerjmMay 21.2016 — It isn't the file_get_contents that is converting your text. It is the result of your use of the 'urlencode' function that does that.
×

Success!

Help @Muhammad_Talha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...