I have a string
$initial_string = "<input type = 'checkbox' name = 'cb[]' value = '[a-zA-Z]'>"
In this I want to match the letters 'cb' and replace it with '1cb'.
The final string should look like this
$final_string = "<input type = 'checkbox' name = '1cb[]' value = '[a-zA-Z]'>"
My code is as follows. But nothing works. I have tried all tricks. Help will be greatly appreciated.
if (preg_match("cb", $initial_string))
{
$pattern = "cb";
$pat = "1cb";
$replacement = "$pat";
$final_string = preg_replace($pattern, $replacement, $initial_string);
echo "$final_string";
}