BrazilMac Posted August 6, 2008 Share Posted August 6, 2008 Hello! Im failry new to PHP and I guess this is a complex thing that I no idea how to do. I have an Ebay URL for an auction, they all look like this: http://cgi.ebay.com/Heavy-Duty-Cuckoo-Clock-Bellow-Part-Wires-5-1-2_W0QQitemZ270262100267QQihZ017QQcategoryZ10020QQssPageNameZWDVWQQrdZ1QQcmdZViewItem It seems all normal auctions have the item number inbetween the "itemZ" and "QQih..." section. Basically, I just need to copy the section in red above (this is the item number)into a variable in PHP. How do I go about reading the URL and just extracting it?? Thanks again!! Herick Link to comment https://forums.phpfreaks.com/topic/118443-how-to-sanitize-a-url-how-do-i-get-a-piece-of-a-url-into-a-variable/ Share on other sites More sharing options...
Xurion Posted August 6, 2008 Share Posted August 6, 2008 Use of regex will do it: <?php $url = 'http://cgi.ebay.com/Heavy-Duty-Cuckoo-Clock-Bellow-Part-Wires-5-1-2_W0QQitemZ270262100267QQihZ017QQcategoryZ10020QQssPageNameZWDVWQQrdZ1QQcmdZViewItem'; $chars = preg_split('/http.*QQitemZ/', $url, -1, PREG_SPLIT_OFFSET_CAPTURE); $chars = preg_split('/QQih.*ViewItem/', $chars[1][0], -1, PREG_SPLIT_OFFSET_CAPTURE); $chars = $chars[0][0]; echo $chars; ?> Link to comment https://forums.phpfreaks.com/topic/118443-how-to-sanitize-a-url-how-do-i-get-a-piece-of-a-url-into-a-variable/#findComment-609703 Share on other sites More sharing options...
BrazilMac Posted August 6, 2008 Author Share Posted August 6, 2008 Man, Thank you so much!!!! This site is AWESOME!!! Link to comment https://forums.phpfreaks.com/topic/118443-how-to-sanitize-a-url-how-do-i-get-a-piece-of-a-url-into-a-variable/#findComment-609785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.