0

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

3
  • 1
    Interesting. Any question/problem where we can help you? How to Ask Commented Aug 23, 2014 at 20:47
  • Would be a lot more helpful if you could provide sample input and output. Commented Aug 23, 2014 at 20:51
  • I did read that. What is that you could not understand from my question? I am just starting with PHP and I have used these functions alone but never together. Commented Aug 23, 2014 at 20:52

1 Answer 1

1

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"
Sign up to request clarification or add additional context in comments.

16 Comments

so sorry. I forgot to mention. My $str is an array. I have it printed twice : $str[0] and $str[1]
That makes your question more complex. I dont understand how it fits into the question above. can you correct the Original question?
I have made the explode function after your function. it still does not work as intended. It is deleting EVERYTHING before, also including the $strtosearch.
I want to have $strtosearch wrapped into "div class="example">$strtosearch</div> . This is why I am making the replacement.
You have an $arr which you want to search for a particular string in it or you have a string and want to search your string? I am confused at what your need is
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.