I have a list of names and I'm using preg_replace to make a certain part of those names bold. I was using str_replace but I needed a limit on it.
However I'm getting the error "Delimiter must not be alphanumeric or backslash". After some research I found out that it's happening because I'm missing slashes on my pattern variable.
However I've been trying and I can't get it right and I'm not finding any example like mine. Thank you for your help.
while($row = $result->fetch_array()) {
$name = $row['name'];
$array = explode(' ',trim($name));
$array_length = count($array);
for ($i=0; $i<$array_length; $i++ ) {
$letters = substr($array[$i], 0, $q_length);
if ($letters = $q) {
$bold_name = '<strong>'.$letters.'</strong>';
$final_name = preg_replace($letters, $bold_name, $array[$i], 1);
$array[$i] = $final_name; }
}