php - preg_match from URL string -


i have string passed through campaign source looks this:

/?source=search%20&utm_source=google&utm_medium=cpc&utm_term=<keyword/>&utm_content={creative}&utm_campaign=<campaign/>&cpao=111&cpca=<campaign/>&cpag=<group/>&kw=<mpl/> 

when present need cut , pass through our form handler can track our campaigns. can check it, hold contents in cookie , pass throughout our site having , issue using preg_match cut , put variables can pass values handler. want end product like:

$utm_source=google; $utm_medium=cpc; $utm_term=<keyword/> 

there no set number of characters, google, bing etc, trying use preg_match first part (utm_source) , stop past want (&) , forth don't understand preg_match enough this.

php should parsing query sting you, $_get. otherwise, php knows how parse query strings. don't use regular expressions or this, use parse_str.

input:

<?php  $str = "/?source=search%20&utm_source=google&utm_medium=cpc&utm_term=<keyword/>&utm_content={creative}&utm_campaign=<campaign/>&cpao=111&cpca=<campaign/>&cpag=<group/>&kw=<mpl/>";  $ar = array(); parse_str($str, $ar); print_r($ar); 

output:

array (     [/?source] => search     [utm_source] => google     [utm_medium] => cpc     [utm_term] => <keyword/>     [utm_content] => {creative}     [utm_campaign] => <campaign/>     [cpao] => 111     [cpca] => <campaign/>     [cpag] => <group/>     [kw] => <mpl/> ) 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -