Charles Yeung
Charles Yeung

Reputation: 38805

Trim an specific HTML tag by PHP

Suppose I have the code below, how can I only remove the HTML tag of <p> and </p>?

Thanks

<p>This is the first line<br /> This is the second line with image <img src="1.jpg" /></p>

Upvotes: 0

Views: 254

Answers (1)

Mark Tomlin
Mark Tomlin

Reputation: 8923

Your looking for the str_replace function.

mixed str_replace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] )

<?php

    $str = '<p>This is the first line<br /> This is the second line with image <img src="1.jpg" /></p>'
    echo str_replace(array('<p>', '</p>'), NULL, $str);

?>

Upvotes: 1

Related Questions