Jump to content

Recommended Posts

Hello

 

I am working on my graduation project and I have a critical problem with my php code and I am just beginner in php coding.

 

I am reading from text file IDs of papers and want to link between the ID that I read form my text file and the XML file so that is my code :

<?php

$file = fopen("abstract/Temp_id.txt","r");

$ids;

while(!feof($file))

{

    $ids = fgets($file);

   

    $xml = simplexml_load_file("abstract/$ids");//abstract is the folder which I save my files and //read from it

   

    $title="bibliomisc =".$xml->articleinfo[0]->bibliomisc;

 

    echo $title;

    echo"<a href=abstract/$ids title='Click to open :)'>$ids</a>";

}

fclose($file);

?>

 

BUT I worked on openssl and it is working if I give it the name of ID e.g.

$xml = simplexml_load_file("abstract/8104317");//it is working but if I read from file I got that error

 

 

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "8104317.xml " in /opt/lampp/htdocs/GP/xml_test.php on line 9

 

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 12

 

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 12

bibliomisc =

8104317.xml

Warning: simplexml_load_file() [function.simplexml-load-file]: I/O warning : failed to load external entity "" in /opt/lampp/htdocs/GP/xml_test.php on line 9

 

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 12

 

Notice: Trying to get property of non-object in /opt/lampp/htdocs/GP/xml_test.php on line 12

bibliomisc =

 

help please :) thanks

 

Link to comment
https://forums.phpfreaks.com/topic/262181-warning-failed-to-load-external-entity/
Share on other sites

The string that fgets returns, contains the newline character(s) at the end of each line. You would want to trim those off, since they are not actually part of the filename being put into the simplexml_load_file statement.

I didn't understand what exactly you said but I think you mean that I should trim(file)

and that is my new code

while(!feof($file))

{

    $ids = fgets($file);

   

    //$url = "$ids";

   

    $xml = simplexml_load_file(trim(fgets($file))

 

but I didn't work :( :( any suggestion please ?

and thanks for you reply

I solved this with the following code

 

$url = trim($ids, " \n");;

    $xml = simplexml_load_file("abstract/$url");

but I got a lot of warning because it reads the last line of my file and it is an empty file so please how to make this code doesn't read the last line which is empty

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.