Preserve Line Breaks - Simple HTML DOM Parser

后端 未结 5 2048
忘掉有多难
忘掉有多难 2021-02-01 18:21

When using PHP Simple HTML DOM Parser, is it normal that line breaks
tags are stripped out?

5条回答
  •  深忆病人
    2021-02-01 18:47

    I know this is old, but I was looking for this as well, and realized there was actually a built in option to turn off the removal of line breaks. No need to go editing the source.

    The PHP Simple HTML Dom Parser's load function supports multiple useful parameters:

    load($str, $lowercase=true, $stripRN=false, $defaultBRText=DEFAULT_BR_TEXT)
    

    When calling the load function, simply pass false as the third parameter.

    $html = new simple_html_dom();
    $html->load("stuff", true, false);
    

    If using file_get_html, it's the ninth parameter.

    file_get_html($url, $use_include_path = false, $context=null, $offset = -1, $maxLen=-1, $lowercase = true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT)
    

    Edit: For str_get_html, it's the fifth parameter (Thanks yitwail)

    str_get_html($str, $lowercase=true, $forceTagsClosed=true, $target_charset = DEFAULT_TARGET_CHARSET, $stripRN=true, $defaultBRText=DEFAULT_BR_TEXT, $defaultSpanText=DEFAULT_SPAN_TEXT)
    

提交回复
热议问题