A rather elegant way to do this is using a regex:
$input = '1234b1';
$pattern = '/b/';
$replacement = '$0 ';
$output = preg_replace($pattern,$replacement,$input);
Running this with PHP's interactive shell:
$ php -a
Interactive mode enabled
php > $input = '1234b1';
php > $pattern = '/b/';
php > $replacement = '$0 ';
php > $output = preg_replace($pattern,$replacement,$input);
php > echo $output;
1234b 1
EDIT: in case you want to skip a line, you update $replacement
with "\$0
"
, or if you want HTML new lines: $0<br>
:
$input = 'abbbbasasjscxxxxc';
$pattern = '/c/';
$replacement = "\$0
"; //'$0<br>' for HTML
$output = preg_replace($pattern,$replacement,$input);
echo $output;