I get this result from web service in php code:
> stdClass Object (
> [Post_Added_Record_ByMenuIDResult] => stdClass Object
> (
> [HTMLStructure] => ثبت انجام شد
> [IsAuthenticated] => 1
> [MenuID] => 1191
> [Password] =>
> [PersonID] => 27598
> [PersonalityID] => 31413
> [RecordValues] =>
> [RoleID] => 5
> [Sexuality_Title] => m
> [UserName] => mr.piri
> ) )
I want to get the opposite phrase in [HTMLStructure]. in this example : ثبت انجام شد
if (strstr( $result, 'HTMLStructure' ) ) {
$HTMLStructurePos=strpos( $result, '[HTMLStructure] =>' );
echo $HTMLStructurePos;
$IsAuthenticatedPos=strpos( $result, ' [IsAuthenticated]' );
echo $IsAuthenticatedPos;
$result2 = substr($result, $HTMLStructurePos, $IsAuthenticatedPos);
echo "<pre>";
print_r($result2);
echo "</pre>";
} else {
echo "Not found";
}
but i get
Not found
in the out put.
I think this is a structure and I have to get the value with the pointer.But does anyone know how?
CodePudding user response:
You get a nested object back from your Web-Service. Simplified as PHP code:
$result = (object)['Post_Added_Record_ByMenuIDResult' => (object)[
'HTMLStructure' => "ثبت انجام شد",
'IsAuthenticated' => 1,
//...
]];
The HTML can be accessed simply like this:
$html = $result->Post_Added_Record_ByMenuIDResult->HTMLStructure;
echo $html; // ثبت انجام شد
Just like HTMLStructure, you also get the values like IsAuthenticated.
CodePudding user response:
i solved this problem by this code:
foreach ($result as $obj)
{
// Here you can access to every object value in the way that you want
$result2 = $obj->HTMLStructure;
}