Jump to content

Varible and classes


NBG
 Share

Recommended Posts

Been out of the "loop" for a while and running into trouble on day one.  Trying to figure it out.

 

Parsing Data from a url and getting   error message "Class '98007214' not found in"

-------------------------------------

code as follows

 

$corpid=array('98007214','98008630');
 
$x = 1;
while ($x<3)
{
 
$data = file_get_contents($url);
$list = new SimpleXMLElement($data);
 
foreach ($list->result->corporationName as $result):
    echo $result;
endforeach;
$x=$x+1;
}
--------------------------
 
So it seems like the $corpid($x) expression is pulling the value it is supposed to be pulling.  but then the error is because its looking for a class?  Never had this issue back in the day and a bit confused on why its just not adding the varible in as text and creating a class error.
Link to comment
Share on other sites

To pull the items of an array and append them to a string you would use: "your url ..." . $corpid[$x]

 

Also note that you should probably check the array key exists, as you're doing 1 and 2 in your loop as $x when your array keys are 0 and 1.  Try something more like ..

 

 

// Number of elements in the array.
$corpid_len = count($corpid);
 
// Loop through starting with 0 and ending with the count - 1
for ($i = 0; $i < $corpid_len; $i++)
{
$url="https://api.eveonline.com/corp/CorporationSheet.xml.aspx?corporationID=" . $corpid[$x];
}
Link to comment
Share on other sites

o7

 

There's also the simpler foreach loop:

foreach ($corpid as $id) {
	$url="https://api.eveonline.com/corp/CorporationSheet.xml.aspx?corporationID=" . $id;
And SimpleXML supports loading directly from a URL so you can skip the file_get_contents() step and do

$list = new SimpleXMLElement($url, 0, true); // true=first argument is a url
Link to comment
Share on other sites

I think one misunderstanding is here:

$corpid=array('98007214','98008630');
$x = 1;
while ($x<3)

Standard arrays are zero-based. That is, a var_dump($corpid) will show that $corpid has indexes of zero and one.

 

Also, when assigning $url, the array $corpid is being used as a function call. So:

From:
$url="https://api.eveonlin...?corporationID=" .$corpid($x); // Not parentheses

To:
$url="https://api.eveonlin...?corporationID=" .$corpid[$x]; // Use brackets
Link to comment
Share on other sites

This thread is more than a year old. Are you sure you have something important to add to it?

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.

 Share

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