CraftHell Posted September 4, 2011 Share Posted September 4, 2011 What im trying to do is grab a list of items from http://ffxiv.yg.com/items?f=c=6.2.7 and display it for me in a blank layout like /item/antelope-sinew-cord?id=10007501 - antelope-sinew-cord - 10007501 /item/carbon-fiber?id=10009304 - carbon-fiber - 10009304 etc etc.. But the code i came up with grabs the data great.. (TOOK ME FOREVER TO FIGURE OUT THE PATTERN ) but i finally managed to get it lol.. anyways the following code is <?php $page_contents = file_get_contents("http://ffxiv.yg.com/items?f=c=6.2.7"); $pattern = '/\/item\/([a-z,-]+[^gil])\?id\=([0-9,]+)/'; $matches = array(); preg_match_all($pattern, $page_contents, $matches); foreach($matches as $item) { echo $item[0] . " - " . $item[1] . " - " . $item[2] . "<BR>"; } ?> It works but not the way im looking.. it gives me data like so /item/antelope-sinew?id=10007504 - /item/antelope-sinew-cord?id=10007501 - /item/carbon-fiber?id=10009304 antelope-sinew - antelope-sinew-cord - carbon-fiber 10007504 - 10007501 - 10009304 Thanks for whomever to take a look, and thanks for your responses Quote Link to comment https://forums.phpfreaks.com/topic/246403-need-help-with-calling-this-array-correctly/ Share on other sites More sharing options...
MikeDean89 Posted September 4, 2011 Share Posted September 4, 2011 Give this a go.. <?php $page_contents = file_get_contents("http://ffxiv.yg.com/items?f=c=6.2.7"); $pattern = '/\/item\/([a-z,-]+[^gil])\?id\=([0-9,]+)/'; preg_match_all($pattern, $page_contents, $matches); $arrRetList = array(); if(!empty($matches)){ foreach($matches as $item) { foreach($item as $pos => $row){ $arrRetList[$pos][] = $row; } //echo $item[0] . " - " . $item[1] . " - " . $item[2] . "<BR>"; } foreach($arrRetList as $row){ echo implode( " - ", $row ) . "<br />"; } } ?> Couldn't spend much time on it but I believe it does what you need it to. Quote Link to comment https://forums.phpfreaks.com/topic/246403-need-help-with-calling-this-array-correctly/#findComment-1265324 Share on other sites More sharing options...
CraftHell Posted September 4, 2011 Author Share Posted September 4, 2011 Thank you so much it works just like i wanted. Now say i wanted to turn that line of code into a function and call it apon multiple websites something like <?php grabdata("http://ffxiv.yg.com/items?f=c=6.2.7"); grabdata("http://ffxiv.yg.com/items?f=c=7"); grabdata("http://ffxiv.yg.com/items?f=c=5"); grabdata("http://ffxiv.yg.com/items?f=c=etcetc"); function grabdata($site){ $page_contents = file_get_contents($site); $pattern = '/\/item\/([a-z,-]+[^gil])\?id\=([0-9,]+)/'; preg_match_all($pattern, $page_contents, $matches); $arrRetList = array(); if(!empty($matches)){ foreach($matches as $item) { foreach($item as $pos => $row){ $arrRetList[$pos][] = $row; } //echo $item[0] . " - " . $item[1] . " - " . $item[2] . "<BR>"; } foreach($arrRetList as $row){ echo implode( " - ", $row ) . "<br />"; } } } ?> also if i wanted to make /item/antelope-sinew?id=10007504 - antelope-sinew - 10007504 /item/antelope-sinew-cord?id=10007501 - antelope-sinew-cord - 10007501 /item/carbon-fiber?id=10009304 - carbon-fiber - 10009304 /item/cotton-yarn?id=10005302 - cotton-yarn - 10005302 /item/crawler-cocoon?id=10005206 - crawler-cocoon - 10005206 /item/dew-thread?id=10005307 - dew-thread - 10005307 /item/diremite-sinew?id=10007510 - diremite-sinew - 10007510 /item/diremite-sinew-cord?id=10007509 - diremite-sinew-cord - 10007509 /item/diremite-web?id=10005306 - diremite-web - 10005306 /item/flax?id=10005204 - flax - 10005204 /item/hempen-yarn?id=10005301 - hempen-yarn - 10005301 /item/hippogryph-sinew?id=10007505 - hippogryph-sinew - 10007505 /item/hippogryph-sinew-cord?id=10007502 - hippogryph-sinew-cord - 10007502 /item/karakul-yarn?id=10005305 - karakul-yarn - 10005305 /item/linen-yarn?id=10005303 - linen-yarn - 10005303 /item/moko-grass?id=10005202 - moko-grass - 10005202 /item/mole-sinew?id=10007507 - mole-sinew - 10007507 /item/mole-sinew-cord?id=10007508 - mole-sinew-cord - 10007508 /item/morbol-vine?id=10009503 - morbol-vine - 10009503 /item/raptor-sinew?id=10007506 - raptor-sinew - 10007506 /item/raptor-sinew-cord?id=10007503 - raptor-sinew-cord - 10007503 /item/straw?id=10005201 - straw - 10005201 /item/woolen-yarn?id=10005304 - woolen-yarn - 10005304 only show: antelope-sinew - 10007504 antelope-sinew-cord - 10007501 carbon-fiber - 10009304 cotton-yarn - 10005302 crawler-cocoon - 10005206 dew-thread - 10005307 diremite-sinew - 10007510 diremite-sinew-cord - 10007509 diremite-web - 10005306 flax - 10005204 hempen-yarn - 10005301 hippogryph-sinew - 10007505 hippogryph-sinew-cord - 10007502 karakul-yarn - 10005305 linen-yarn - 10005303 moko-grass - 10005202 mole-sinew - 10007507 mole-sinew-cord - 10007508 morbol-vine - 10009503 raptor-sinew - 10007506 raptor-sinew-cord - 10007503 straw - 10005201 woolen-yarn - 10005304 :confused: Quote Link to comment https://forums.phpfreaks.com/topic/246403-need-help-with-calling-this-array-correctly/#findComment-1265417 Share on other sites More sharing options...
CraftHell Posted September 4, 2011 Author Share Posted September 4, 2011 wow it wont let me modify my last post.. i figured out the second part to make it show just antelope-sinew - 10007504 antelope-sinew-cord - 10007501 carbon-fiber - 10009304 cotton-yarn - 10005302 crawler-cocoon - 10005206 dew-thread - 10005307 diremite-sinew - 10007510 diremite-sinew-cord - 10007509 diremite-web - 10005306 flax - 10005204 hempen-yarn - 10005301 hippogryph-sinew - 10007505 hippogryph-sinew-cord - 10007502 karakul-yarn - 10005305 linen-yarn - 10005303 moko-grass - 10005202 mole-sinew - 10007507 mole-sinew-cord - 10007508 morbol-vine - 10009503 raptor-sinew - 10007506 raptor-sinew-cord - 10007503 straw - 10005201 woolen-yarn - 10005304 I changed foreach($arrRetList as $row){ echo implode( " - ", $row ) . "<br />"; } to foreach($arrRetList as $row){ echo $row[1] . " - " . $row[2] . "<BR>"; } still cant figure out the functions problem :/ Quote Link to comment https://forums.phpfreaks.com/topic/246403-need-help-with-calling-this-array-correctly/#findComment-1265423 Share on other sites More sharing options...
CraftHell Posted September 4, 2011 Author Share Posted September 4, 2011 lol im sorry for these multiple post its not letting me edit any of mine.. but i got it all to work lol just took some tweaking.. heres the code <?php function grabdata($site){ $page_contents = file_get_contents($site); $pattern = '/\/item\/([a-z,-]+[^gil])\?id\=([0-9,]+)/'; preg_match_all($pattern, $page_contents, $matches); $arrRetList = array(); if(!empty($matches)){ foreach($matches as $item) { foreach($item as $pos => $row){ $arrRetList[$pos][] = $row; } //echo $item[0] . " - " . $item[1] . " - " . $item[2] . "<BR>"; } foreach($arrRetList as $row){ //echo implode( " - ", $row ) . "<br />"; echo $row[1] . " - " . $row[2] . "<BR>"; } } } grabdata("http://ffxiv.yg.com/items?f=c=6.2.7"); grabdata("http://ffxiv.yg.com/items?f=c=6.2"); grabdata("http://ffxiv.yg.com/items?f=c=ETC.."); grabdata("http://ffxiv.yg.com/items?f=c=ETC.."); grabdata("http://ffxiv.yg.com/items?f=c=ETC.."); grabdata("http://ffxiv.yg.com/items?f=c=ETC.."); grabdata("http://ffxiv.yg.com/items?f=c=ETC.."); ?> Quote Link to comment https://forums.phpfreaks.com/topic/246403-need-help-with-calling-this-array-correctly/#findComment-1265425 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.