Note that there are some explanatory texts on larger screens.

plurals
  1. POfile_get_contents working for some .txt files and not others?
    primarykey
    data
    text
    <p>I have a script written by a friend that gets all the contents from a directory of .txt files and uploads them into a database alongside some other information. </p> <p>aka: filename | Contents</p> <p>Each file's contents - simple text info - is stored in a corresponding database entry. It's been working very well so far, <strong>but the contents of a new bunch of text files simply aren't being read.</strong> The filenames are read fine and that info is imported into the database easily. It's just the actual contents. Old .txt files that I've imported previously still are imported perfectly.</p> <p>Examples of files are here: <a href="http://pintail.eu/php/working.txt" rel="nofollow">Working</a> / <a href="http://pintail.eu/php/notworking.txt" rel="nofollow">Not-Working</a></p> <p><strong>Long story short</strong> - does anyone know why the contents of some .txt files can be read and not others? Encoding issues possibly, etc? (though they're from the same person and look identical) I'm losing my mind. </p> <p>Thanks!</p> <pre><code>$dir = 'text'; //createxml(10);exit; $time_start = microtime(true); $files = scandir($dir); natsort($files); foreach ($files as $v) { if ($v != "." &amp;&amp; $v != ".." &amp;&amp; $v != "thumbs" &amp;&amp; $v != ".DS_Store") { //get work done $text = file_get_contents($dir.'/'.$v); //get volume, page, county $ta = explode('.',$v); $ma = explode('_',$ta[0]); $last = count($ma)-1; $volume = ''; $year = '1999'; for ($i = 0; $i &lt; $last; ++$i) { $volume .= $ma[$i].'_'; } $volume = $mysqli-&gt;real_escape_string(rtrim($volume,'_')); $pagenr = $mysqli-&gt;real_escape_string($ma[$last]); $ntext = $mysqli-&gt;real_escape_string(getmtext($text)); $pdf = 'http://griffiths.****.ie/gv4/thoms/'.$volume.'/'.$volume.'_pg'.str_pad($pagenr, 4, "0", STR_PAD_LEFT).'.pdf'; $thumb = 'http://griffiths.****.ie/gv4/thoms/'.$volume.'/thumbs2/'.$volume.'_'.str_pad($pagenr, 4, "0", STR_PAD_LEFT).'.jpg'; //create sql $echo[$volume] .= "('','$year','$pagenr','$volume','$ntext','$pdf','$thumb'),"; $excl[$volume]=true; } } // check if there is volume already in DB foreach ($excl as $k =&gt; $v) { $volumes .= "'$k',"; } $volumes = rtrim($volumes,','); $excls =''; if ($result = $mysqli-&gt;query("SELECT DISTINCT volume FROM thoms_copy2 WHERE volume in ($volumes)")) { //found volumes already in DB while ($r = $result-&gt;fetch_array(MYSQLI_NUM)) //we only need the new volumes, so we will ignore the rest unset($echo[$r[0]]); $result-&gt;close(); } //create mysql string foreach ($echo as $k =&gt; $v) { $echot .= $v.','; } $echot = rtrim($echot,','); if ($echot) {// if i have something to insert //insert into DB $sql = "INSERT INTO `thoms_copy2` (`id`,`year`,`main_page`, `volume`, `texty`, `pdf`, `thumb`) VALUES $echot"; if ($result = $mysqli-&gt;query($sql)) { echo "Done."; //create the XML file createxml($mysqli-&gt;affected_rows); } else { printf("Error message: %s\n", $mysqli-&gt;error); echo "&lt;br&gt;&lt;br&gt;$sql"; } } else { echo "Done. Nothing new."; } $time_end = microtime(true); $time = $time_end - $time_start; echo "&lt;br&gt;$time"; //functions =============================================================== function getmtext($str) { $text = ''; $words = str_word_count($str, 1); foreach ($words as $word) { if ($word[0] &gt;= 'A' &amp;&amp; $word[0] &lt;= 'Z') if (strlen($word)&gt;1) $text .= $word.' '; } return $text; } </code></pre>
    singulars
    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.
 

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