Note that there are some explanatory texts on larger screens.

plurals
  1. POIndicate encoding of XML file using objDOM ->load()
    primarykey
    data
    text
    <p>I am trying to read an XML file and then input the obtained value into a database. Then entire process works great , as long as there are no special characters in the XML. the XML is formatted as :</p> <pre><code>&lt;link&gt; &lt;name&gt;Cech&lt;/name&gt; &lt;club&gt;Chelsea&lt;/club&gt; &lt;/link&gt; </code></pre> <p>In case the <code>name</code> tag encloses a name like <code>Suárez</code>, i get the error: <code>Input is not proper UTF-8, indicate encoding ! Bytes: 0xE1 0x72 0x65 0x7A in file:///C:/wamp/www/ADB/links.xml, line: 1857 in C:\wamp\www\ADB\phptry.php on line 14</code> , where line 1857 has the name <code>Suárez</code> . i tried including the <code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; </code> at the beginning of the file and using the <code>utf8_encode(file_get_contents('links.xml'))</code> but it doesnt work. Any suggestions? this is my working php code:</p> <pre><code>&lt;?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } $objDOM = new DOMDocument(); //$content = utf8_encode(file_get_contents('links.xml')); $objDOM-&gt;load('links.xml'); //make sure path is correct $note = $objDOM-&gt;getElementsByTagName("link"); // for each note tag, parse the document and get values for // tasks and details tag. foreach( $note as $value ) { $player = $value-&gt;getElementsByTagName("name"); $player_name = $player-&gt;item(0)-&gt;nodeValue; $playername = addslashes($player_name); $club = $value-&gt;getElementsByTagName("club"); $club_name = $club-&gt;item(0)-&gt;nodeValue; // $points = $value-&gt;getElementsByTagName("points"); // $point_value = $points-&gt;item(0)-&gt;nodeValue; $sql = "INSERT INTO pilayers (name,club) VALUES('$playername','$club_name')"; mysql_select_db('players'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } echo "Entered data successfully\n"; } mysql_close($conn); ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload