Jump to content

Need help with calling this Array() correctly..


CraftHell

Recommended Posts

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  :wtf:) 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  8)

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.

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: :confused:

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 :/

 

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..");

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.