Saleha,
Its showing absolutely correct error message. Did you notice that you are
suppose to pass an object as a parameter on this function? If you are doing so
$xml should be an object already and IFF it is, then why are you using $xml (as
an object) in the preg_replace function as 3rd parameter? According to
preg_replace function the 3rd parameter should be anything but array and object.
Thats why its failing. Example:
Syntax definition for preg_replace:
mixed preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int
$limit = -1 [, int &$count ]] )
So, the 3rd parameter generally has to be a string. Also notice that you are
returning the value of that line 224 into $xml back again. This is
programmatically correct, but do you think you are running out of variable
names? Use some other variable name here.
To make your function working, I think you do not need object to be passed onto
this function, you need pure xml as a string into this.
Hope you will understand your problem now.
Thanks
Yamin
--- In
phpexperts@yahoogroups.com, Saleha Latif <salehalatif@...> wrote:
>
> The Function & error on line 224 i put double quotations as its has "/*" in
actual function it has single quotations.
>
>
> Catchable fatal error: Object of class stdClass could not be converted to
string in D:\wamp\www\booking\uapi\air_v16_0\test.php on line 224
>
>
> function formatXmlString($xml){
>
> Â Â line 224 => $xml = preg_replace("/(>)(<)(\/*)/", "$1\n$2$3", $xml);
>    $token     = strtok($xml, "\n");
>    $result    = '';
>    $pad       = 0;
>    $matches   = array();
> Â Â Â while ($token !== false) :
> Â Â Â Â Â Â Â if (preg_match('/.+<\/\w[^>]*>$/', $token, $matches)) :
> Â Â Â Â Â Â Â Â Â $indent=0;
> Â Â Â Â Â Â Â elseif (preg_match('/^<\/\w/', $token, $matches)) :
> Â Â Â Â Â Â Â Â Â $pad--;
> Â Â Â Â Â Â Â Â Â $indent = 0;
> Â Â Â Â Â Â Â elseif (preg_match('/^<\w[^>]*[^\/]>.*$/', $token, $matches)) :
> Â Â Â Â Â Â Â Â Â $indent=1;
> Â Â Â Â Â Â Â else :
> Â Â Â Â Â Â Â Â Â $indent = 0;
> Â Â Â Â Â Â Â endif;
>        $line   = str_pad($token, strlen($token)+$pad, ' ',
STR_PAD_LEFT);
> Â Â Â Â Â Â Â $result .= $line . "\n";
>        $token  = strtok("\n");
>        $pad   += $indent;
> Â Â Â endwhile;
> Â Â Â return $result;
> }
>
>
>
> ________________________________
> From: shiplu <shiplu.net@...>
> To:
phpexperts@yahoogroups.com
> Sent: Thursday, February 23, 2012 2:10 PM
> Subject: Re: [phpXperts] need array response in xml
>
>
> Â
> It seems formatXmlStringfunction is failing. Are you sure this function takes
stdClassas parameter and returns string? Could you paste the function body
here?
>
>
> --Â
> Shiplu.Mokadd.im
> ImgSign.com | A dynamic signature machine
> Innovation distinguishes between follower and leader
>