Extracting partial text from an Array

I have a one item array whos contents, using var_dump() are as follows:

array(1) {
	[0]=>  object(stdClass)#519 (23) {
		["ID"]=>  string(3) "907"
		["post_author"]=>  string(1) "2"
		["post_date"]=>  string(19) "2010-07-07 18:48:31"
		["post_date_gmt"]=>  string(19) "2010-07-07 18:48:31"
		["post_content"]=>  string(532) "The details of the listing will go here. They will all be stored as custom fields relative to this page. Then they will be displayed below using whatever CSS markup is appropriate.[mappress]"
		["post_title"]=>  string(8) "432 Hill"
		["post_excerpt"]=>  string(523) "The details of the listing will go here. They will all be stored as custom fields relative to this page. Then they will be displayed below using whatever CSS markup is appropriate."
		["post_status"]=>  string(7) "publish"
		["comment_status"]=>  string(4) "open"
		["ping_status"]=>  string(4) "open"
		["post_password"]=>  string(0) ""
		["post_name"]=>  string(8) "677-shazzll"
		["to_ping"]=>  string(0) ""
		["pinged"]=>  string(0) ""
		["post_modified"]=>  string(19) "2010-07-09 17:09:33"
		["post_modified_gmt"]=>  string(19) "2010-07-09 17:09:33"
		["post_content_filtered"]=>  string(0) ""
		["post_parent"]=>  string(1) "0"
		["guid"]=>  string(40) "http://www.yourwebsite/test/?p=907"
		["menu_order"]=>  string(1) "0" 
		["post_type"]=>  string(4) "post"
		["post_mime_type"]=>  string(0) ""
		["comment_count"]=>  string(1) "0" } } 

I am trying to access this array as $pageposts[0] and continue to get errors and cannot access it. The error is: Catchable fatal error: Object of class stdClass could not be converted to string

This array is the contents of one record in a database, and I am trying to extract the “?p=907” text from the array item.

Can anyone offer any advice on how to access this array item or how to capture that particular text component?

Thanks.

:lol:

As for me, what I was “on” was Lack Of Sleep combined with a dose of Distraction. Both easily obtainable and legal too :wink:

I’m sure glad you guys came along because my previous reply was off the mark in more ways than one. Wrong key->value pair and wrong sntax to boot :blush: So PLEASE ignore it.

Where does it say that the object is serialized? Have you even seen how a serialized item looks like? It looks something like “a:2:{i:0;s:4:“pleh”;i:1;R:1;}”. The output of the var_dump in the dwzemens’ post clearly shows that the object is NOT serialized.

The fatal error: Object of class stdClass could not be converted to string is because you are trying to use an object in a string context (like echo it) and its class doesn’t implement the __toString magic method.


$parts = explode( '?', $pageposts[0]->guid, 2 ); 
parse_str( $parts[1], $queryStringVariables );
// should output 907
echo $queryStringVariables['p'];

Assuming the array represented in your first post is $array then to get the guid property which contains the text that you want, you would access $array[0]->guid. What you do with that value depends on what you want; the full URL or just the ?p=907 part of it.

To the other posters, what are you guys on because I want some. :blush:

hi,

you have received serialized object
in order to deserialize do this


$obj = deserialize($pageposts[0]);
echo $obj->id;

basically, when you receive object its probably serialized in order to be transferred, so when something is serialized it needs to be deserialized in order to use it as an object.

I hope this will help you

Did you try

$pageposts[0]->[‘ID’]