php - Custom user agent parser -
for parsing user agent found ua-parser, powerfull, don't want parse browser user agent, want parse custom user agent :
paperl installer (windows; p; 32bit; ver 2.0.3; os: 5.1.2600 sp 3.0 nt; x32c;) bookl installer (windows; b; 64bit; ver 1.0; os: 6.1.7601 sp 1.0 nt; x64c;)
now how can fetch paperl
or bookl
, ver
, x32c
or x64c
agent ?
this thing :) not need regex. can other strings easily.
function trim_string($s) { $s = trim($s, ";"); $s = trim($s, ";)"); return $s; } $string = "paperl installer (windows; p; 32bit; ver 2.0.3; os: 5.1.2600 sp 3.0 nt; x32c;)"; $array = explode(" ", $string); $firstitem = trim_string($array[0]); // return paperl $version = trim_string($array[6]); // return 2.0.3 $last = trim_string(end($array)); // return x32c echo $firstitem. " ". $version. " ". $last; // return paperl 2.0.3 x32c
Comments
Post a Comment