-1

Hello i have this part of php code

    $google_url = "http://uclassify.com/browse/uClassify/Sentiment/ClassifyText?readkey=jnsdnjdsnjnjsdnjsnjdsd&text=".$text."&version=1.01";

    $result = file_get_contents($google_url);


$obj = simplexml_load_string($result);

$zaab = toArray($obj);

echo($zaab);

and the answer i get is

<?xml version="1.0" encoding="UTF-8" ?>
<uclassify xmlns="http://api.uclassify.com/1/ResponseSchema" version="1.01">
    <status success="true" statusCode="2000"/>
    <readCalls>
    <classify id="cls1">
        <classification textCoverage="0.6">
            <class className="negative" p="0.999984"/>   <-----p_value
            <class className="positive" p="1.60692e-005"/>     <-----p_value
        </classification>
    </classify>
    </readCalls>
</uclassify>

how can i access p_values?

no after updating it gives me an error having to do with toArray()

Mpampinos Holmens
  • 1,879
  • 5
  • 18
  • 34
  • Possible duplicate of [Best XML Parser for PHP](http://stackoverflow.com/questions/188414/best-xml-parser-for-php) and many, many, many others. – DaveRandom Mar 06 '12 at 16:37
  • And what does the `toArray()` function look like? What error does it give you? – DaveRandom Mar 06 '12 at 17:40

2 Answers2

1

You can get the all *p*s attribute values by looping through all *class*es like this:

$classes = $obj->readCalls->classify->classification->class;
    foreach ($classes as $class) {
        $p_val = $class->attributes()->p;
        echo $p_val . "<br />";
    }

I see you also tried to convert the xml string to array, probably the simplest way to do it is:

$json = json_encode($obj);
$xml_array = json_decode($json,TRUE);

To see the results use:

echo "<pre>";
print_r($xml_array);
echo "</pre>";
Dan C
  • 44
  • 3
0

Use a xml parser.

http://php.net/manual/en/book.xml.php

jsimpson
  • 391
  • 1
  • 5