Reputation: 357
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?
Upvotes: 3
Views: 3505
Reputation: 198117
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";
Upvotes: 6