PHP: how to prevent unwanted line breaks

I use PHP to create basic HTML. Tags are always the same, but the actual links / headers correspond to PHP variables:

$string = '<p style="..."><a href="'.$html[$i].'"><strong><i>'.$title[$i].'</i></strong></a>
<br>';
echo $string;
fwrite($outfile, $string);

The resulting html, both reflected (when I look at the source of the page), and in a simple txt file that I write, read as follows:

    <p style="..."><a href="http://www.example.com
"><strong><i>Example Title
</i></strong></a></p>
<br>

While this works, this is not exactly what I want. It looks like PHP adds a line break every time I break a line to insert a variable. Is there a way to prevent this behavior?

+3
source share
3 answers

HTML- ( pre text-wrap: pre), trim() , .

, ,

var_dump(preg_match('/^\n|\n$/', $variable));

( , , PHP \n ).

+2
+1

- , . :

$newstring =  mb_substr($string_w_line_break,[start],[length],'UTF-8');

, html.

0

Source: https://habr.com/ru/post/1776356/


All Articles