PHP Put Span Class into Brackets regex -
this have far: $phones = "samsung galaxy s8~lg g6~iphone 7 plus~ motorola z2"; $phones = str_replace("galaxy s", '<span class="galaxy">galaxy</span>', $phones); $value = preg_replace('/(\d+.*?)(~)/', '($1)$2', $phones . "~"); $value = "<li>". str_replace("~", ",</li><li>", substr($value,0,-1)) . "</li>"; echo $value; and result is: samsung galaxy (8), lg g(6), iphone (7 plus), motorola z(2) what i'm trying put span class inside brackets be: samsung ( galaxy 8 ), lg g(6), iphone (7 plus), motorola z(2) thanks pattern demo/explanation code: ( demo ) $phone='samsung galaxy s8~lg g6~iphone 7 plus~ motorola z2'; $match='/galaxy s(\d+)/'; $replace='( <span class="galaxy">galaxy</span> $1 )'; echo preg_replace($match,$replace,$phone); unrendered output: sam...