whatf
whatf

Reputation: 6458

php regex parsing, keep the contents of the tag intact

input string:

<sometag> valid content .....
....line break    some more valid content</sometag>

output string:

    valid content.....
......line break some more valid content

Please let me know how to do it, thanks.

Upvotes: 0

Views: 140

Answers (3)

Joseph Silber
Joseph Silber

Reputation: 219930

$string = '<sometag> valid content .....
....line break    some more valid content</sometag>';

$string = preg_replace('/<[^>]+>/', '', $string);

Upvotes: 0

Grigor
Grigor

Reputation: 4049

$oldstring = "<sometag> valid content ..... ....line break    some more valid content</sometag>";

$newstring = preg_replace('/\b<sometag>\b/', '', $oldstring); 
$newstring = preg_replace('/\b</sometag>\b/', '', $newstring);
$newstring = preg_replace('<br/>', '', $newstring);

assuming by line break you mean <br/>

Upvotes: 0

dee-see
dee-see

Reputation: 24078

You can use the strip_tags() PHP function instead of a regular expression. See manual.

<?php
  $str = "<sometag> valid content .....
  ....line break    some more valid content</sometag>";
  echo strip_tags($str);

  //valid content .....
  //....line break    some more valid content
?>

Upvotes: 4

Related Questions