Marius S
Marius S

Reputation: 287

Combine substr_replace with str_replace in php

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

Upvotes: 0

Views: 1212

Answers (1)

Paullo
Paullo

Reputation: 2127

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"

Upvotes: 1

Related Questions