Finding a substring within a PHP array?
<p>I have a PHP script that loops through each row of a CSV file and organizes each line into an array:</p>

<pre><code>$counter = 0;
    $file = file($ReturnFile);
    foreach($file as $k){
        if(preg_match('/"/', $k)==1){
            $csv[] = explode(',', $k);
            $counter++;
         }
     }

    ...

    while($x&lt;$counter){
        $line=$csv[$x];
</code></pre>

<p>This works; my question is about how to find a substring within each line. This:</p>

<pre><code>    foreach($line as $value){
        if($value==$name_search){
            // action
</code></pre>

<p>works if the value of <code>$line</code> is exactly equal to the value of <code>$name_search</code> (<code>$name_search</code> is a person's last name). However, this doesn't work if there is a space or additional characters in the value of <code>$line</code> (for example: <code>$line</code> equal to "Wilson (ID: 345)" or "Wilson " won't match a <code>$name_search</code> value of "Wilson".</p>

<p>So far I've tried:</p>

<pre><code>if(strpos($value, $res_name_search) !== false){

if(substr($value, 0, strrpos($value, ' '))==$res_name_search){

if(substr(strval($value), 0, strrpos(strval($value), ' '))==$res_name_search){
</code></pre>

<p>without success ... Do I have a syntax error and/or is there a better way to accomplish this?</p>