Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP substr() REALLY slow when not taking first part of string
    primarykey
    data
    text
    <p>I have a text file that has about 5,000 lines with each line being about 200 characters long. Each line actually contains 6 different pieces of data that I've been using <code>substr()</code> to break apart. For example, on each line, characters 0 - 10 contain the Client#, characters 10-20 contain the Matter#, etc. This is all well and good and was running faster than I even needed it to.</p> <p>My problems arose when I was told by my boss that the client number has 4 leading zeros and they need to be stripped off. So I thought, no problem - I just changed my first <code>substr()</code> function from <code>substr(0, 10)</code> (start at 0 and take 10 characters) and changed it to <code>substr(4, 6)</code> (starting at the 4th character and just taking 6) which will skip the 4 leading zeros and I'll be good to go.</p> <p>However, when I changed the <code>substr(0, 10)</code> to <code>substr(4,6)</code> the process grinds to a halt and takes <strong>forever</strong> to complete. Why is this?</p> <p>Here is a snippet from my code:</p> <pre><code>// open the file $file_matters = fopen($varStoredIn_matters,"r") or exit("Unable to open file!"); // run until the end of the file while(!feof($file_matters)) { // place current line in temp variable $tempLine_matters = fgets($file_matters); // increment the matters line count $linecount_matters++; // break up each column $clientID = trim(substr($tempLine_matters, 0, 10)); // THIS ONE WORKS FINE //$clientID = trim(substr($tempLine_matters, 4, 6)); // THIS ONE MAKES THE PROCESS GRIND TO A HALT!! $matterID = trim(substr($tempLine_matters, 10, 10)); //$matterID = trim(substr($tempLine_matters, 15, 5)); $matterName = trim(substr($tempLine_matters, 20, 80)); $subMatterName = trim(substr($tempLine_matters, 100, 80)); $dateOpen = trim(substr($tempLine_matters, 180, 10)); $orgAttorney = trim(substr($tempLine_matters, 190, 3)); $bilAttorney = trim(substr($tempLine_matters, 193, 3)); $resAttorney = trim(substr($tempLine_matters, 196, 3)); //$tolCode = trim(substr($tempLine_matters, 200, 3)); $tolCode = trim(substr($tempLine_matters, 200, 3)); $dateClosed = trim(substr($tempLine_matters, 203, 10)); // just does an insert into the DB using the variables above } </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