Reputation: 699
I have a string:
$string = '<p>[Some_string value="2" width="3" someMoreInfoHere]</p>'
I need help writing a regular expression on finding and replacing both <p>
and </p>
with ''
.
I know that I can use a string replace as here:
$string = str_replace("<p></p>", "", $string);
However, I only want the paragraph begin, and end to be replaced, when the occurance of either a paragraph begin tag, followed imidiatly by a squared bracket like so:
'<p>['
and in the case of a close bracket, followed imidieatly by a closing paragraoh tag, like so:
']</p>'
I hope this makes sense, I am a little confused myself :/
Upvotes: 2
Views: 500
Reputation: 6112
$string = str_replace(array('<p>[', ']</p>'), array('[', ']'), $string);
Hope it's what you're looking for.
No need for a regular expression.
Upvotes: 4
Reputation: 9303
Did you know about strip_tags()?
$string = '<p>[Some_string value="2" width="3" someMoreInfoHere]</p>';
echo strip_tags($string);
Upvotes: 1
Reputation: 699
Sorry for the confusion guys and especially @Hamza:
I figurred it out myself, daaahhhhhhh
This is what i was looking for:
$string = str_replace("<p>[", "[", $string);
$string = str_replace("]</p>", "]", $string);
Upvotes: 2