Greetings!
I am new with preg_replace(). Consider the following string taken out of a flat file:
...<stuff before>...
Receiver ID read from STB|000867493231Receiver ID read from label|000867493231
...<stuff after>...
I need to replace this string to that (notice the red bolded pipe symbol before the 2nd occurence of the word Receiver):
...<stuff before>...
Receiver ID read from STB|000867493231|Receiver ID read from label|000867493231
...<stuff after>...
So I wrote this script to test preg_replace():
<?php
$section="Receiver ID read from STB|000867493231Receiver ID read from label|000867493231";
$okay = preg_match('/[0-9]+\Receiver/', $section);
if ( $okay == 1 ) { echo "Match found!\n"; }
else { echo "Match not found!\n"; }
$section = preg_replace('/[0-9]+\Receiver/','|$1', $section);
echo $section;
?>
Even though I find a match, the replacement statement does not work. Instead, I get this
Receiver ID read from STB|| ID read from label|000867493231
What am I doing wrong here? Can someone please help me? Thank you.
Al.