php在特定字符后查找并替换字符串

php在特定字符后查找并替换字符串,php,string,str-replace,Php,String,Str Replace,我有一个包含少量“*”字符的长字符串,我想找到所有这些字符并替换它们+它们后面的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(

我有一个包含少量“*”字符的长字符串,我想找到所有这些字符并替换它们+它们后面的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
$over\u string=strlen($story)-1;
对于($i=0;$i)
应该能带你去你想去的地方

或者,如果您想用*后面的8个匹配字符替换链接的核心部分,则可以使用

$story = preg_replace('/\*(.{8})/', '<a href="#">$1</a>', $story);
$story=preg\u replace('/\*(.{8})/','','$story);

你能举一个原始字符串的例子吗?
$story = preg_replace('/\*(.{8})/', '<a href="#">$1</a>', $story);