php - Matching pattern that is within brackets -
i trying create mobile detection class supposed strip user agent simple basic string this:
output: mozilla/5.0 (*linux x86_64*) applewebkit/* (khtml, gecko) chrome/* safari/*
from this:
input: (http_user_agent) mozilla/5.0 (x11; linux x86_64) applewebkit/537.17 (khtml, gecko) chrome/24.0.1312.69 safari/537.17
i using this: /[0-9.-]{4,}/i
pattern strip numbers , get:
result of far above pattern: mozilla/5.0 (x11; linux x86_64) applewebkit/* (khtml, gecko) chrome/* safari/*
but problem how remove x11;
want pattern remove everything after first opening bracket , till first empty space think right way. acceptable alternative able remove brackets @ pattern.
any suggestions?
ps: needing solve problem mobile detection , dependency on browscap. please no downvotes please!
ps2: main purpose of observe mobile clients , desktop. after tweak give info os, , etc..
replace x11; not khtml:
preg_replace('/\([^,)]*? ([^\)]+)/','(*\1*',$agent);
explained demo here: http://regex101.com/r/vl6gt1
php regex preg-match
No comments:
Post a Comment