doubomudichen0832
2014-08-23 20:43
浏览 129
已采纳

在php中将substr_replace与str_replace结合使用

What I am trying to do is to replace a specific string with another only if found in a certain position.

php:

$substr = substr_replace($string, $replacement, $stringstart);
$str = str_replace($quoted, $replacement, $str);

I plan to replace $string with $replacement in the string $str but only after $stringstart characters.

I also have $stringend. If I could also use that(because I know exactly the length of $replacement), it would be great. This is optional though

图片转代码服务由CSDN问答提供 功能建议

我要做的是只在特定位置找到特定字符串才能替换另一个字符串。

php:

  $ substr = substr_replace($ string,$ replacement,$ stringstart); 
 $ str = str_replace($ 引用,$ replacement,$ str); 
   
 
 

我打算用字符串$ str中的$ replacement替换$ string,但只能在$ stringstart字符之后。

我也有$ stringend。 如果我也可以使用它(因为我确切知道$ replacement的长度),那就太好了。 这是可选的,但

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dou44364983 2014-08-23 21:19
    已采纳

    I think this is what you are looking for:

    $strToSearch="There is no need searching here. The search need to start here";
    echo str_replace("need to start","started",substr($strToSearch, 32, strlen($strToSearch)));
    

    This will produce the result:

    "The search started here"
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题