Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access an object with a hash character in the key name?

Tags:

json

object

php

How do you access a PHP object that has a # in the $key name?

Example:

[image] => stdClass Object 
       ( 
       [#text] => http://userserve-ak.last.fm/serve/_/85003/Red+Hot+Chili+Peppers.jpg 
       [name] => original 
       [width] => 937 
       [height] => 1276 
       )

I want to access the #text property, but $image->#text doesn't work because PHP interprets the # as the start of a comment.

How do I do this?

like image 209
Fred Stevens-Smith Avatar asked Dec 05 '22 21:12

Fred Stevens-Smith


2 Answers

You can try with:

$image->{'#text'}
like image 200
hsz Avatar answered Dec 10 '22 11:12

hsz


maybe like this: (not sure)

$image->{"#text"}
like image 37
Tim Baas Avatar answered Dec 10 '22 11:12

Tim Baas