5 Replies - 617 Views - Last Post: 25 May 2012 - 09:30 AM Rate Topic: -----

#1 Derpost  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 26-February 11

how can i print this data? (object data)

Posted 25 May 2012 - 06:29 AM

Var_dump result:
object(stdClass)#2 (1) {
 [0]=>
  array(5) {
    ["title"]=>
    string(71) "Tarihte Bugün Neler Olmuş? Bugünün önemli olayları! | Ttbugun.com"
    ["keywords"]=>
    string(47) "tarih,tarih dersi,tarihte bugün,günün sözü"
    ["description"]=>
    string(69) "Tarihte bugün olan olaylar ve diğer tarihi olayların hepsi burada."
    ["author"]=>
    string(17) "Yusuf Ali Bozkır"
    ["id"]=>
    string(1) "1"
  }
}


using var_dump:
var_dump($header->headers);


How can i print title,description and others?

Is This A Good Question/Topic? 0
  • +

Replies To: how can i print this data? (object data)

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: how can i print this data? (object data)

Posted 25 May 2012 - 06:58 AM

foreach ($object as $property) should work in this case. otherwise:
echo $obj->title, $obj->headers, $obj->description; // etc.

Was This Post Helpful? 0
  • +
  • -

#3 Derpost  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 26-February 11

Re: how can i print this data? (object data)

Posted 25 May 2012 - 07:26 AM

View PostDormilich, on 25 May 2012 - 06:58 AM, said:

foreach ($object as $property) should work in this case. otherwise:
echo $obj->title, $obj->headers, $obj->description; // etc.

I tried use as below but not run.
$header->headers->title;

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: how can i print this data? (object data)

Posted 25 May 2012 - 07:28 AM

EDIT: doh, looking carefully helps …

if it were valid, $header->headers->0->title would work. but it seems better to not fetch/cast your data into an object.

This post has been edited by Dormilich: 25 May 2012 - 07:30 AM

Was This Post Helpful? 0
  • +
  • -

#5 Derpost  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 26-February 11

Re: how can i print this data? (object data)

Posted 25 May 2012 - 08:02 AM

View PostDormilich, on 25 May 2012 - 07:28 AM, said:

EDIT: doh, looking carefully helps …

if it were valid, $header->headers->0->title would work. but it seems better to not fetch/cast your data into an object.

syntax error :)
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3577
  • View blog
  • Posts: 10,442
  • Joined: 08-June 10

Re: how can i print this data? (object data)

Posted 25 May 2012 - 09:30 AM

I never said it would work (I even said explicitly, that it is invalid), only what the structure determines.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1