Question: I'm trying to strip all the dots and then get the number, and NAME[X] as an output.

My output is:

```
NAME..................................................................................................3
NAME2...................................................................................................24
NAME3...............................................................................................................................................5
NAME4.......................347
NAME5............................................................................................7
NAME6......................................................................9

```

I've tried something like this so far:

```
function introExcerpt($id = null, $introExcerptCut = null)
    {

        $fileInfo['intro'] = 'my string';
        $introExcerpt = trim($fileInfo['intro']);

        $lines = preg_split('/\r\n|\r|\n/', $introExcerpt);
        $intro = '<div class="toc"><ul class="toc">';

        for ($i = 0; $i < count($lines); $i++) {
           // if (isset($lines[$i]) && substr(trim($lines[$i]), -1) !== '.') {
                $intro.= $lines[$i].'<br />';
            //}
        }
        $intro .= '</div></ul>';

        return $intro;
    }

```

Answer: 
Not sure exactly what your output should look like, but you may try just running `preg_replace` directly on the variable containing all lines:

```php
$lines = preg_replace("/(NAME\d+)\.+(\d+)/", "$1[$2]", $lines);

```

This would generate the following output based on your sample input:

```
NAME[3]
NAME2[24]
NAME3[5]
NAME4[347]
NAME5[7]
NAME6[9]

```
You can use the following function:

```
function introExcerpt($str, $id = null, $introExcerptCut = null)
{

    $fileInfo['intro'] = $str;
    $introExcerpt = trim($fileInfo['intro']);

    $lines = preg_split('/\r\n|\r|\n/', $introExcerpt);
    $intro = '<div class="toc"><ul class="toc">';

    for ($i = 0; $i < count($lines); $i++) {
        $intro .= '<li>';
        $tmpLineArray = explode('.', $lines[$i]);
        array_filter($tmpLineArray, function ($value) {
            return !is_null($value) && $value != '';
        });

        foreach ($tmpLineArray as $value) {
            $intro .= $value . ' ';
        }

        $intro .= '</li>';
    }
    $intro .= '</ul></div>';

    return $intro;
}

```

It is splitting the entire row into array using dot as separator and filters out the empty elements.