1

How do I echo an object attribute

Is it possible to echo value='$embed" of the $video_data object below?

My goal is to make a description meta tag for http://perfecthealthmap.com/video-library/1 that populates with this information for the selected video.

<meta name="description" content="<?php echo($video_data->$embed);?>" />

Doesn't work.

Below is the information I am trying to echo into the description tag. Please help.

$video_data .= $embed;
$video_data .= "<br><table width='100%' border=0 cellpadding=2 cellspacing=2><tr><td width='50'>URL:</td><td><input type='text' style='font-family: verdana; font-size: 8pt; border: 1px solid #EAEAEA; width: 300px; height: 20px;' onclick='select()' value='http://".$_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'] . "'></td></td></tr><tr><td width='50'>Embed:</td><td><input type='text' style='font-family: verdana; font-size: 8pt; border: 1px solid #EAEAEA; width: 300px; height: 20px;' onclick='select()' value='$embed'></td></td></tr></table>";
4

2 回答 2

2

如果它是一个公共成员变量,那么您可以通过以下方式访问它:

echo $video_data->embed;
于 2012-12-15T21:13:15.947 回答
0

如果属性的名称是“$embed”,则必须将对象转换为关联数组并像这样回显您的新变量

echo $ObjectCastInArray['$embed'];

除非对象来自 json_decode,否则您可以直接将 json 字符串转换为关联数组,将 json_decode 函数中的第二个参数设置为 true

json_decode ($yourJsonString, true); // will return an associative array

我希望这个能帮上忙!

于 2012-12-15T22:33:13.147 回答