Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with pregmatch

    So Im trying to parse an XML feed and everything seems to be in order. Yet it will only parse the first variable '$online' correctly. The second variable returns nothing. Any idea why, anyone?


    PHP Code:
    <?php 
            $h3tag 
    $_GET['h3tag']; 
            if    (empty(
    $h3tag))    {
                
    $h3tag 'blank';
            }
            
            
    $h3tag str_replace(" ","%20",$h3tag);
                
            
    $ch curl_init();
            
    $timeout 5;
            
    curl_setopt ($chCURLOPT_URL'http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag='$h3tag);
            
    curl_setopt ($chCURLOPT_RETURNTRANSFER1);
            
    curl_setopt ($chCURLOPT_CONNECTTIMEOUT$timeout);
            
    $in1 curl_exec($ch);
            
    curl_close($ch);

            
    preg_match('#<Info>(.+?)</Info>#',$in1$online1);
            
    preg_match('#<Info2>(.+?)</Info2>#',$in1$status1);

            
    $online $online1[1];
            
    $status $status1[1];

            
    $output '<div> Online Status: ' $online '</div><div> Status: ' $status '</div>';
            echo 
    $output;
    ?>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Give us an example of what this variable might be: $h3tag

    So we can view the XML ourselves.

  • #3
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    http://duncanmackenzie.net/services/...scarytigermoth

    Info2 will only have a variable if the user is signed on. The link above shows a user signed on.

    Edit: Well now the user is offline. Normally it will show this:

    Code:
    <?xml version="1.0" ?> 
    - <XboxInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <AccountStatus>Gold</AccountStatus> 
    - <PresenceInfo>
      <Valid>true</Valid> 
      <Info>Playing Texas Hold'em</Info> 
      <Info2>Scenario - Single Player Playing a hand</Info2> 
      <LastSeen>2007-11-05T13:41:03-06:00</LastSeen> 
      <Online>true</Online> 
      <StatusText>Online</StatusText> 
      <Title>Texas Hold'em</Title> 
      </PresenceInfo>
      <State>Valid</State> 
      <Gamertag>Babylons rise</Gamertag> 
      <ProfileUrl>http://live.xbox.com/member/Babylons rise</ProfileUrl> 
      <TileUrl>http://tiles.xbox.com/tiles/rN/63/1Wdsb2JhbC9CCgUMBhkAGAENL3RpbGUvMC8yODAwNgAAAAAAAAD6mN6M.jpg</TileUrl> 
      <ReputationImageUrl>http://live.xbox.com/xweb/lib/images/gc_repstars_external_20.gif</ReputationImageUrl> 
      <GamerScore>22098</GamerScore> 
      <Zone>Underground</Zone>
    Last edited by residual; 11-05-2007 at 07:42 PM.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    First of all, arrays start with item 0, not 1

    $online = $online1[0];
    $status = $status1[0];

    Secondly,
    I would think you would be looking here:

    preg_match('#<StatusText>(.+?)</StatusText>#',$in1, $status1);

    instead of here:

    preg_match('#<Info2>(.+?)</Info2>#',$in1, $status1);

  • #5
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No I want Info2 variable

    And unfortunately setting those vars to 0 did nothing as well

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    darn! double-foiled!

    Maybe it has something to do with preg_match
    when it should be preg_match_all?

  • #7
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    You really should use SimpleXML
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #8
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yea unfortunately my host had php 4 installed and simplexml is php 5. I've requested the upgrade and I will reattempt the code using simplexml. However still doesn't explain why my code doesn't work

  • #9
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Enjoy the last 2 months of PHP4 support
    PHP4 XML functions aren't that easy to use, but still a lot better than trying to use regex. http://www.php.net/manual/en/ref.xml.php
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •