PHP Echo a large block of text

后端 未结 11 1043
南方客
南方客 2021-01-30 21:00

Im new to PHP and I can\'t figure out what the rules are for using the echo function. For example, if I need to echo a large block of css/js, do I need to add echo to each line

11条回答
  •  死守一世寂寞
    2021-01-30 21:29

    Echoing text that contains line breaks is fine, and there's no limit on the amount of text or lines you can echo at once (save for available memory).

    The error in your code is caused by the unescaped single quotes which appear in the string.

    See this line:

    $('input_6').hint('ex: myname@example.com');
    

    You'd need to escape those single quotes in a PHP string whether it's a single line or not.

    There is another good way to echo large strings, though, and that's to close the PHP block and open it again later:

    if (is_single()) {
      ?>
     
    
     
     
     
     
     
     
     
    
      

    Or another alternative, which is probably better for readability, is to put all that static HTML into another page and include() it.

提交回复
热议问题