Im trying to remove some '<p>'
tags from a string returned by wordpress. I've had a look at the php documentation but I can't seem to find a function that will alow me to define a string and then strip that string from a variable. Im new to php and I realize this must be a pretty simple operation. Any suggestions?
Asked
Active
Viewed 1,698 times
1
5 Answers
2
you could use str_replace http://www.php.net/manual/en/function.str-replace.php

peaceman
- 2,549
- 19
- 14
-
1+1: Although `strip_tags()` is probably what Thomas needs, still `str_replace()` is what Thomas asked for. – Martin Hennings May 10 '11 at 15:01
1
Try this:
$myString = "<p>whatever you want in your string</p>";
$newString = str_replace(["<p>","</p>"], "", $myString);
echo $newString;
Explanation
Using str_replace
, you can replace one or more strings with one or more other strings. In this case, we're replacing any <p>
and </p>
tags with an empty string.

Dave
- 28,833
- 23
- 113
- 183
0
I think you're looking for either of str_replace()
or (more likely, since you only want to replace some of them) preg_match()
.

Denis de Bernardy
- 75,850
- 13
- 131
- 154
tags.
– Thomas May 10 '11 at 15:53