Customizing SMF > SMF Coding Discussion

Regex help

(1/2) > >>

4Kstore:
Hi to all...
I have a problem with regex expressions....

Ex: i have this url format:

--- Code: ---ed2k://|file|Game.Of.Thrones.S01E09.Baelor.PROPER.720p.HDTV.x264-ORENJI.mkv|1565034720|01B71CB10E9702ED5C07E63CBA41B501|h=RKXVCVYZON7LNLBANPYBTRMABERLGEZE|/
--- End code ---

i need get the hash of this ed2k url, the sintaxis is always the same

In this case i need:

--- Code: ---01B71CB10E9702ED5C07E63CBA41B501
--- End code ---

resuming, i need the code between: "|" and "|h="

and the part i need save in a variable...

$match = 01B71CB10E9702ED5C07E63CBA41B501;

Can someone help me?
Cheers

manixless:
Could be better...


$url = ...

preg_match_all('/\|([0-9A-Z].*?)\|/s', $url, $hashes);

echo $hashes[1][1];

manixless:
best option:

preg_match_all('/\|([0-9A-Z]{32})\|/s', $url, $hashes);



echo $hashes[1][0];

4Kstore:
Thanks manfred!!
Works perfect...
Regards!

MrPhil:
How about

--- Code: ---$url_list = explode('|', $url);
$match = $url_list[4];
--- End code ---

This assumes that $url is the actual string as shown in your post. You may have to adjust the element number if it's just a part of that line.

Navigation

[0] Message Index

[#] Next page

Go to full version