doubomudichen0832
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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dou44364983
    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"
    
    点赞 评论

相关推荐