How to remove one instance of one string in PHP?
- by Jane
I have a open source editor on the cms that I am making that automatically inserts a
<br />
tag at the beginning of the post it submits to the database. This makes validation a pain, since even though there is no real text being submitted, the form still accepts the break tag as input and prevents the "Please enter some text" error from showing.
So I tried to remove the opening break tag by filtering my input like this:
substr($_POST['content'], 6);
This works as long as the user doesn't press the backspace a couple of times which removes the break tag in which case the first 8 characters of the post gets removed even if they are not a break tag.
So how can I remove the first 6 characters of the input ONLY if those first 6 characters are composed of the break tag. Also I don't want to remove all break tags, only the one at the very beginning of the post.