3

How do I remove entire characters from a string starting from a particular string position to another position, and shift the rest to merge with this starting position?

I'm working with HTML contents. So take this for example.

</a></h4><p class="pdesc">When a private satellite encounters .... and it is found to ...</p></div></div>.....<p class="pdesc">Before leavingon his .... </p> ...... <p class="pdesc"> .... </p>

So now I want to remove all characters in between

<p class="pdesc"> - to - </p>.

of every occurrence.

I can search for this (strpos) and get the starting and the ending positions, but then manually deleting them and shifting strings from then on will be too tedious.

Is there a built in function or a simple way to do it?

1

1 Answer 1

6

You can do this with the substr_replace­Docs function:

$var = 'ABCDEFGH:/MNRPQR/';

/* Delete 'MNRPQR' from $var. */
echo substr_replace($var, '', $start = 10, $length = -1) . "<br />\n";
Sign up to request clarification or add additional context in comments.

Comments

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.