php - Unable to read file having # in directory name or in file name
Get the solution ↓↓↓Solution:
#
is a special character in URLs. It marks the beginning of the fragment.
In order to use its literal value in an URL it has to be properly URL-encoded.
Pass the file name to function urlencode()
to produce the correct URL for it. It takes care of all characters that are special in URLs (/
,&
,=
,#
,?
,%
, etc.)
$filename = 'ds_FWREF#1801\msg_1_ds_FW SYSREF#180133.json';
$content = file_get_contents('http://localhost/project/'.urlencode($filename));
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: xml parsing error: no root element found
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.