in reply to Highlight a substring
To add highlight to HTML given start $index and $length:
substr($str, $start_idx, $length) = '<b>' . substr($str, $start_idx, $length) . '</b>';
Once you add searching, it looks like:
my $index = 0; my $replace = "<b>$seq</b>"; while (($index = rindex($str, $seq, $index)) >= 0) { substr($str, $index, length($seq)) = $replace; }
Update: Optimized
|
|---|