「*」文字をほとんど含まない長い文字列があります。これらすべての文字を見つけて、それらとその後の 8 文字を置き換え、それらを別の文字列に置き換えたいと考えています。これを行う最善の方法は何ですか?これは私がやろうとした方法です:
$over_string=strlen($story)-1;
for ($i=0; $i<$over_string; $i++){
if($story[$i]=='*'){
$id_substr=substr($story, $i+1,8);
$name_player_change=some_function($id_substr);
$id_to_replace='*'.$id_substr;
$name_to_place='<a href="#">'.$name_player_change.'</a>';
$story=str_replace($id_to_replace,$name_to_place,$story);
}//if
}//for