3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $addr = "http://example.com/?foo=bar&utm_source=google&pk_rdm=1235#2&utm_medium=cpc&utm_campaign=auchan-fil_rouge"; $xmlstr = <<<XML <xml> <medium val="organic"> <source val=""> <campaign val=""> <lever3 val="seo">foo</lever3> <lever2 val="seo">bar</lever2> <lever1 val="trafic_gratuit" /> </campaign> </source> </medium> <medium val="cpc"> <source val=""> <campaign val="remarketing"> <lever3 val="sem-remarketing" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> </source> <source val="leguide"> <campaign val=""> <lever3 val="comparateur-leguide" /> <lever2 val="comparateur" /> <lever1 val="trafic_payant" /> </campaign> </source> <source val="google"> <campaign val="marque"> <lever3 val="sem-marque-google" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> <campaign val="auchan-fil_rouge"> <lever3 val="sem-marque-google" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> <campaign val="horsmarque"> <lever3 val="sem-hors-marque-google" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> </source> <source val="bing"> <campaign val="auchan-fil_rouge"> <lever3 val="sem-marque-yahoo_bing" /> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> <campaign val="marque"> <lever3 val="sem-marque-yahoo_bing"/> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> <campaign val="horsmarque"> <lever3 val="sem-horsmarque-yahoo_bing"/> <lever2 val="sem" /> <lever1 val="trafic_payant" /> </campaign> </source> </medium> <medium val="cpa"> <source val="affilinet"> <campaign val=""> <lever3 val="affiliation" /> <lever2 val="affiliation" /> <lever1 val="trafic_payant" /> </campaign> </source> </medium> </xml> XML; $xml = new SimpleXMLElement($xmlstr); // Parse the url. $results = explode("&", explode("?", $addr)[1]); $tags = array ('utm_medium=', 'utm_source=', 'utm_campaign='); $sources = array('medium_val' => '', 'source_val' => '','campaing_val' => ''); foreach($results as $result){ foreach($tags as $key => $tag) { if (($offset = stripos($result, $tag)) !== false) $sources[$key] = substr($result, strlen($tag)); } } $results = $xml->xpath("//medium[@val='{$sources[0]}']/source[@val='{$sources[1]}']/campaign[@val='{$sources[2]}']/*"); $leviers = array("levier3", "levier2", "levier1"); echo $results[0]->attributes(); //foreach ($results as $key => $result) { // echo " {$leviers[$key]} => {$result->attributes()}\n"; //}
Output for 5.4.0 - 7.1.0
sem-marque-google
Output for 4.4.3 - 4.4.9, 5.1.0 - 5.1.1, 5.1.3 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/tkLB0 on line 83
Process exited with code 255.
Output for 4.4.2, 5.1.2
Parse error: syntax error, unexpected '[' in /in/tkLB0 on line 84
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/tkLB0 on line 83
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/tkLB0 on line 83
Process exited with code 255.