Thomas
Thomas

Reputation: 5099

PHP Filtering strings

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?

Upvotes: 1

Views: 1706

Answers (5)

Dave
Dave

Reputation: 29141

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.

Upvotes: 1

Denis de Bernardy
Denis de Bernardy

Reputation: 78571

I think you're looking for either of str_replace() or (more likely, since you only want to replace some of them) preg_match().

Upvotes: 0

Headshota
Headshota

Reputation: 21449

strip_tags($mystring); // this will remove all tags

Upvotes: 1

Pekka
Pekka

Reputation: 449813

strip_tags() might help you.

Upvotes: 0

peaceman
peaceman

Reputation: 2609

you could use str_replace http://www.php.net/manual/en/function.str-replace.php

Upvotes: 2

Related Questions