Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your could use <a href="http://php.net/explode" rel="nofollow"><code>explode()</code></a> to split your string into lines ; and, then, for each line, a simple Regular expression, with the <a href="http://php.net/preg_match" rel="nofollow"><code>preg_match()</code></a> function, to match the parts that interest you.</p> <p>For example, something like this :</p> <pre><code>$str = &lt;&lt;&lt;STR 22222 hihihi 33333 hihihi kjhkh hihihi STR; foreach (explode(PHP_EOL, $str) as $line) { if (preg_match('/^([^\s]+)\s+(.*)$/', $line, $m)) { var_dump($m[1], $m[2]); } } </code></pre> <p>Would get you :</p> <pre><code>string '22222' (length=5) string 'hihihi' (length=6) string '33333' (length=5) string 'hihihi' (length=6) string 'kjhkh' (length=5) string 'hihihi' (length=6) </code></pre> <p><br> Notes about the regex I used :</p> <ul> <li>starts at beginning of string : <code>^</code></li> <li>matches anything that is not a white character (tabulation, newline, space) : <code>[^\s]</code> <ul> <li>one or more times : <code>[^\s]+</code></li> <li>capturing it : <code>([^\s]+)</code></li> </ul></li> <li>matches anything that is a white character : <code>\s</code> <ul> <li>one or more times : <code>\s+</code></li> </ul></li> <li>matches anything any number of times : <code>.*</code> <ul> <li>capturing it : <code>(.*)</code></li> </ul></li> <li>and, finally, end of string : <code>$</code></li> </ul> <p><br> Now, as you are working with a file as input, and not a string, you might want to read the file line by line, not fetching the whole file into memory ; for that, see the <a href="http://php.net/function.fgets" rel="nofollow"><code>fgets()</code></a> function -- there is an example on its manual page.</p>
 

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