How to remove one instance of one string in PHP?
Posted
by Jane
on Stack Overflow
See other posts from Stack Overflow
or by Jane
Published on 2010-03-25T08:36:13Z
Indexed on
2010/03/25
8:43 UTC
Read the original article
Hit count: 293
php
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.
© Stack Overflow or respective owner