views:

290

answers:

1

Hello

34|http://v19.lscache8.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor,oc:U0dWRlZUVF9FSkNNNl9OTlhF&fexp=902210&algorithm=throttle-factor&itag=34&ipbits=0&burst=40&sver=3&expire=1271696400&key=yt1&signature=583C4A85FA65B6B9782B8B4B5E1F1C08D9EADCA3.5B28033470580BC52EB92A1CB71DBAFE0C4A2A8D&factor=1.25&id=cf3cec58d98073dc,5|http://v24.lscache4.c.youtube.com/videoplayback?ip=0.0.0.0&sparams=id,expire,ip,ipbits,itag,algorithm,burst,factor,oc:U0dWRlZUVF9FSkNNNl9OTlhF&fexp=902210&algorithm=throttle-factor&itag=5&ipbits=0&burst=40&sver=3&expire=1271696400&key=yt1&signature=7B74075BAA26B05A028B2219FD52D7A45197F555.A8878413DC7BB3FFAB0C9219CBD3FCDD7221B440&factor=1.25&id=cf3cec58d98073dc

How to parse this text for:

34
http://... (before ,5|)
5
http://... to end

Previously it was done so:

if (preg_match_all('#|(.*?),#', $urlmap, $b)) {
}

Sorry for baaaaad english

+3  A: 

Try using:

if(preg_match_all('#\d+\|(.*?),#',$urlmap,$b))

there is a number before | we need to consider and also | is a meta char in regex, so we need to escape it. But this not give you the complete URL.

Instead you can split the input on the pattern digits| as:

$arr = preg_split('/\d+\|/',$input,-1, PREG_SPLIT_NO_EMPTY  );

EDIT:

Working example

codaddict
Your code echoing : 34 with 'htpp://' but 2nd not echoing cause dont'have symbol ',' in the end..How fix?
Isis
@Isis: I've updated my answer with a link to ideone.
codaddict
@unicornaddict: thank you! symbol ',' in the end must be remove) thank you!
Isis