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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.