Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 31st October 2011, 19:06
alleks alleks is offline
Senior Member
 
Join Date: Nov 2010
Posts: 157
Thanks: 9
Thanked 9 Times in 9 Posts
Default PHP check the response of the api

Hi, I am trying to check that if the response of the api contains something like

PHP Code:
<error>
<
message>No Videos found!</message>
<
code>####</code>
</error
To do a show_error() in codeigniter. I've tried it with preg_match but no success for me. Any help would be greatly appreciated.
Reply With Quote
Sponsored Links
  #2  
Old 31st October 2011, 19:46
alleks alleks is offline
Senior Member
 
Join Date: Nov 2010
Posts: 157
Thanks: 9
Thanked 9 Times in 9 Posts
Default

I have tried this but with no success

PHP Code:
if (preg_match('#<?xml version="1.0"  standalone="yes"?>\s*<error>\s*<message>(.*)</message>\s*<code>(.*)</code>\s*</error>#i', $videosJson));
for this

PHP Code:
<?xml version="1.0"  standalone="yes"?>
    <error>
        <message>No Videos found!</message>
        <code>2001</code>
    </error>
Reply With Quote
  #3  
Old 1st November 2011, 08:54
alleks alleks is offline
Senior Member
 
Join Date: Nov 2010
Posts: 157
Thanks: 9
Thanked 9 Times in 9 Posts
Default

Ok I've managed to do it by doing this:

PHP Code:

if (strpos($videosJson'<error>'))
            {
                
preg_match('/<message>(.+?)<\/message>/'$videosJson$match);
                
show_error("<strong>$tag</strong>: $match[1]");
            } 
Reply With Quote
  #4  
Old 1st November 2011, 08:58
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 35,421
Thanks: 812
Thanked 5,205 Times in 4,081 Posts
Default

As the returned error is a XML document, you could have parsed it with simplexml like this to get a object of the error:

$xml = simplexml_load_string($videosJson);
print_r($xml);
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #5  
Old 1st November 2011, 10:05
alleks alleks is offline
Senior Member
 
Join Date: Nov 2010
Posts: 157
Thanks: 9
Thanked 9 Times in 9 Posts
 
Default

Oh cool, thanks till. I've never worked with xml till now so I didn't even bother on searching some function like json_decode for xml but seem that it's the one you just said.

But knowing that the solution I posted also works, I will keep that one for now.

Thanks again,
Alex
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with ispconfig 3 staff007 Installation/Configuration 4 10th October 2011 21:17
ISP Config not working in mandriva 2008 bigdavid889 Server Operation 8 28th February 2008 20:05
network issues now it says "401 The web site is blocked by administrator" Check General 3 26th February 2008 14:22
php script injections Grizzly General 21 18th July 2006 08:55


All times are GMT +2. The time now is 06:14.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.