5

Currently I am trying to return a publicly available XML resource, though when I use var_dump($resource) it returns string(4390) " ".

I am using CURL to retrieve the resource, and it successfully returns other resources. There's clearly something there (as you can see there is 4390 characters!) but it is not returning successfully.

I have tried wrapping it in utf8_encode though this has made no difference.

I have also tried returning it using print_r and <pre> tags though this too returned nothing.

Any help here would be great!

Charles
  • 50,943
  • 13
  • 104
  • 142
Ollie
  • 544
  • 4
  • 22
  • 1
    Only because you can't see the characters, it does not mean they are not there. For example, if you're viewing this inside the browser and that are 4390 spaces, you will only see one. – hakre Sep 28 '11 at 11:17
  • If you go to it directly it's not blank, it's got quite a lot of XML data stored in it. I have just copied the XML into a char counter and it returns 4384 characters. – Ollie Sep 28 '11 at 11:19

3 Answers3

10

To display non-displayable characters from strings, don't use var_dump but print out a hex-dump of the string, for example

echo bin2hex($resource);

using bin2hexDocs, but the link above has more alternatives to offer. Take what suits your debug needs best.

Edit: In case you're actually outputting HTML or XML elements, use htmlspecialcharsDocs:

echo htmlspecialchars($result);
Community
  • 1
  • 1
hakre
  • 193,403
  • 52
  • 435
  • 836
  • This returns a random load of characters, i.e. 3c3f786d6c2076657273696f6e3d22312e30223f3e0d0a0d0a0d.... – Ollie Sep 28 '11 at 11:23
  • That are one [hexadecimal value](http://en.wikipedia.org/wiki/Hexadecimal) (`00` to `FF`) of each character. You can use a better hex dump function that will display both: hex and printable characters if it's hard for you to read. See the linked question, it has multiple answers with more choices. – hakre Sep 28 '11 at 11:25
  • Thanks, though really what we need to be able to do is simply use this XML data in a script. It clearly exists and is being returned, though I'm having trouble being able to use it. – Ollie Sep 28 '11 at 11:35
  • What's your issue with the XML? – hakre Sep 28 '11 at 11:38
  • @Ollie I have the same issue as you. I want to use the XML string I get from the server. When I try to create [SimpleXMLElement](http://php.net/manual/en/class.simplexmlelement.php) object I get an empty object. How can I solve it? – user08 Jul 25 '17 at 08:14
0

What type of text is in the xml? If there are just html tags try to view the source code of the internet page. Maybe they wont be displayed because your browser interpret the html and dont show the tags

alphanyx
  • 1,647
  • 2
  • 13
  • 18
  • It looks like this: ` ...` – Ollie Sep 28 '11 at 11:29
  • 1
    You're looking for `htmlspecialchars`, see my [updated answer](http://stackoverflow.com/questions/7582302/string-is-not-empty-but-not-appearing-when-using-var-dump/7582389#7582389). – hakre Sep 28 '11 at 11:36
0

Or you can use Kint instead of var_dump to display the debug output. It will show the most information about the dumped variables in the most readable way. Needless to say it displays html effortlessly too.

Screenshot:

Kint screenshot
(source: github.io)

raveren
  • 17,799
  • 12
  • 70
  • 83