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='); foreach($results as $result){ foreach($tags as $key => $tag) { if (($offset = stripos($result, $tag)) !== false) $visitorInfo["$tableName[$key]"] = substr($result, strlen($tag)); } } $results = $xml->xpath("//medium[@val='{$medium_val}']/source[@val='{$source_val}']/campaign[@val='{$campaign_val}']/*"); $leviers = array("levier3", "levier2", "levier1"); echo $results[0]->attributes(); //print_r($results); foreach ($results as $key => $result) { echo " {$leviers[$key]} => {$result->attributes()}\n"; }
Output for 7.0.0 - 7.1.0
Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: medium_val in /in/NRQJq on line 94 Notice: Undefined variable: source_val in /in/NRQJq on line 94 Notice: Undefined variable: campaign_val in /in/NRQJq on line 94 Notice: Undefined offset: 0 in /in/NRQJq on line 97 Fatal error: Uncaught Error: Call to a member function attributes() on null in /in/NRQJq:97 Stack trace: #0 {main} thrown in /in/NRQJq on line 97
Process exited with code 255.
Output for hhvm-3.10.0 - 3.12.0
Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: medium_val in /in/NRQJq on line 94 Notice: Undefined variable: source_val in /in/NRQJq on line 94 Notice: Undefined variable: campaign_val in /in/NRQJq on line 94 Notice: Undefined index: 0 in /in/NRQJq on line 97 Fatal error: Uncaught exception 'BadMethodCallException' with message 'Call to a member function attributes() on a non-object (null)' in /in/NRQJq:97 Stack trace: #0 {main}
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: medium_val in /in/NRQJq on line 94 Notice: Undefined variable: source_val in /in/NRQJq on line 94 Notice: Undefined variable: campaign_val in /in/NRQJq on line 94 Notice: Undefined offset: 0 in /in/NRQJq on line 97 Fatal error: Call to a member function attributes() on null in /in/NRQJq on line 97
Process exited with code 255.
Output for 5.5.0 - 5.5.35
Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: tableName in /in/NRQJq on line 90 Notice: Undefined variable: medium_val in /in/NRQJq on line 94 Notice: Undefined variable: source_val in /in/NRQJq on line 94 Notice: Undefined variable: campaign_val in /in/NRQJq on line 94 Notice: Undefined offset: 0 in /in/NRQJq on line 97 Fatal error: Call to a member function attributes() on a non-object in /in/NRQJq on line 97
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Fatal error: Call to a member function attributes() on a non-object in /in/NRQJq on line 97
Process exited with code 255.
Output for 5.2.3 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/NRQJq on line 83
Process exited with code 255.
Output for 4.4.3 - 4.4.9, 5.1.0 - 5.1.1, 5.1.3 - 5.2.2
<br /> <b>Parse error</b>: syntax error, unexpected '[' in <b>/in/NRQJq</b> on line <b>83</b><br />
Process exited with code 255.
Output for 4.4.2, 5.1.2
<br /> <b>Parse error</b>: syntax error, unexpected '[' in <b>/in/NRQJq</b> on line <b>84</b><br />
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
<br /> <b>Parse error</b>: parse error, unexpected '[' in <b>/in/NRQJq</b> on line <b>83</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error in <b>/in/NRQJq</b> on line <b>83</b><br />
Process exited with code 255.