Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to grab the full contents of the value utm_campaign from the $page variable using the following PHP:

$page = "utm_source=google&utm_campaign=Test | Test - Exact&utm_test=test";
preg_match_all('#utm_campaign=([^s&]+)#', $page, $matches);
var_dump($matches);

However the above var_dump only outputs the following:

Test

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
110 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try parse_str instead:

$page = "utm_source=google&utm_campaign=Test | Test - Exact&utm_test=test";
$res = [];
parse_str($page, $res);
var_dump($res);

This gives you:

array(3) { ["utm_source"]=> string(6) "google" ["utm_campaign"]=> string(19) "Test | Test - Exact" ["utm_test"]=> string(4) "test" }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...