Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use <a href="http://uk3.php.net/manual/en/function.token-get-all.php" rel="nofollow noreferrer"><code>token_get_all()</code></a> to get all the tokens from a PHP file e.g.</p> <pre><code>&lt;?php $fileStr = file_get_contents('file.php'); foreach (token_get_all($fileStr) as $token) { if ($token[0] == T_CONSTANT_ENCAPSED_STRING) { echo "found string {$token[1]}\r\n"; //$token[2] is line number of the string } } </code></pre> <p>You could do a really dirty check that it isn't being used as an array index by something like:</p> <pre><code>$fileLines = file('file.php'); //inside the loop and if $line = $fileLines[$token[2] - 1]; if (false === strpos($line, "[{$token[1]}]")) { //not an array index } </code></pre> <p>but you will really struggle to do this properly because someone might have written something you might not be expecting e.g.:</p> <pre><code>$str = 'string that is not immediately an array index'; doSomething($array[$str]); </code></pre> <hr> <p><strong>Edit</strong> As Ant P says, you would probably be better off looking for <code>[</code> and <code>]</code> in the surrounding tokens for the second part of this answer rather than my <code>strpos</code> hack, something like this:</p> <pre><code>$i = 0; $tokens = token_get_all(file_get_contents('file.php')); $num = count($tokens); for ($i = 0; $i &lt; $num; $i++) { $token = $tokens[$i]; if ($token[0] != T_CONSTANT_ENCAPSED_STRING) { //not a string, ignore continue; } if ($tokens[$i - 1] == '[' &amp;&amp; $tokens[$i + 1] == ']') { //immediately used as an array index, ignore continue; } echo "found string {$token[1]}\r\n"; //$token[2] is line number of the string } </code></pre>
    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