开发者

php regex parsing, keep the contents of the tag intact

input string:

<sometag> valid content .....
....line break    some开发者_如何学Go more valid content</sometag>

output string:

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

Please let me know how to do it, thanks.


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
?>


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

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


$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/>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜