Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Since we've had several answers, I decided to test them all and benchmark them. I used this paths to test:</p> <p><code>$from = "/var/www/sites/web/mainroot/webapp/folder/sub/subf/subfo/subfol/subfold/lastfolder/";</code> NOTE: if it is a folder, you have to put a trailing slash for functions to work correctly! So, <code>__DIR__</code> will not work. Use <code>__FILE__</code> instead or <code>__DIR__ . '/'</code></p> <p><code>$to = "/var/www/sites/web/mainroot/webapp/folder/aaa/bbb/ccc/ddd";</code></p> <p><strong>RESULTS: (decimal separator is comma, thousand separator is dot)</strong></p> <ul> <li>Function by Gordon: result <strong>CORRECT</strong>, time for 100.000 execs <strong>1,222</strong> seconds</li> <li>Function by Young: result <strong>CORRECT</strong>, time for 100.000 execs <strong>1,540</strong> seconds</li> <li>Function by Ceagle: result <strong>WRONG</strong> (it works with some paths but fails with some others, like the ones used in the tests and written above)</li> <li>Function by Loranger: result <strong>WRONG</strong> (it works with some paths but fails with some others, like the ones used in the tests and written above)</li> </ul> <p><strong>So, I suggest that you use Gordon's implementation! (the one marked as answer)</strong></p> <p>Young's one is good too and performs better with simple directory structures (like "a/b/c.php"), while Gordon's one performs better with complex structures, with lots of subdirectories (like the ones used in this benchmark).</p> <hr> <p>NOTE: I write here below the results returned with <code>$from</code> and <code>$to</code> as inputs, so you can verify that 2 of them are OK, while other 2 are wrong:</p> <ul> <li>Gordon: <code>../../../../../../aaa/bbb/ccc/ddd</code> --> CORRECT</li> <li>Young: <code>../../../../../../aaa/bbb/ccc/ddd</code> --> CORRECT</li> <li>Ceagle: <code>../../../../../../bbb/ccc/ddd</code> --> WRONG</li> <li>Loranger: <code>../../../../../aaa/bbb/ccc/ddd</code> --> WRONG</li> </ul>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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