parse mobpartners xml feed for text creatives

Started on the old forum in January 2012 · view the original in the archive · old links redirect here

No replies · 573 views · started 14 years ago · 1 min read

GumSlone Administrator Principal · 1,690 posts #1

so here is the script which parses mobpartners xml feed and creates an array with text creatives:

generate your xml file at MobPartner - Mobile Affiliate Network - Mobile CPA Campaigns - Home dont forget to check the option: Display promotions

function parse_mobpartners_feed($feed_file)
{
    $xml = simplexml_load_file($feed_file,'SimpleXMLElement',LIBXML_NOCDATA);
    foreach($xml->catalog->campaign AS $campaign)
    {
  $countries = gum_foreach($campaign->actions->action->countries->country);
  foreach($countries AS $country)
  {
   unset($crs);
   $creatives = gum_foreach($country->creatives->creative);
   foreach($creatives AS $creative)
   {
    
    if($creative->format=='Text')
    {
     $cr['creative_url'] = (string)$creative->click_url;
     $cr['creative_text'] = (string)$creative->content;
     $crs[] = $cr;
    }
    
   }
   if(is_array($crs))
   {
    $cc = (string)$country->country_name;
    if (isset($arr[$cc]['creatives']))
    {
     $arr[$cc]['creatives'] = array_merge($arr[$cc]['creatives'],$crs);
    }
    else
    $arr[$cc]['creatives'] = $crs;
   }
  }
  
    }
    return $arr;
}
function gum_foreach($vars)
{
    if(isset($vars[0]))
    {
  foreach($vars AS $var)
  {
   $arr[] = $var;
  }
    }
    else
    {
  $arr[] = $vars;
    }
    return $arr;
}

array will look like this:

    [KG] => Array
        (
            [creatives] => Array
                (
                    [0] => Array
                        (
                            [creative_url] => http://c.mobpartner.mobi/?s=112519&a=402&p=9728
                            [creative_text] => Click here to find images!!
                        )

                    [1] => Array
                        (
                            [creative_url] => http://c.mobpartner.mobi/?s=112519&a=402&p=9910
                            [creative_text] => Click here to find videos!!
                        )

                )

        )

Added after 12 minutes:

usage example:

$feed_file = 'test/test.xml';
$arr = parse_mobpartners_feed($feed_file);
$country_code = 'ES'; /* for country code detection use mod_geoip or other ip to country solutions */
if(isset($arr[$country_code]))
{
    $rand = rand(0, count($arr[$country_code]['creatives'])-1);
    echo '<a href="'.$arr[$country_code]['creatives'][$rand]['creative_url'].'">'.$arr[$country_code]['creatives'][$rand]['creative_text'].'</a>';
}

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close