I’m using PHP to create some basic HTML. The tags are always the same, but the actual links/titles 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 resultant html, both as echoed (when I view the page source) and in the simple txt file I’m writing to, reads as follows:
<p style="..."><a href="http://www.example.com
"><strong><i>Example Title
</i></strong></a></p>
<br>
While this works, it’s not exactly what I want. It looks like PHP is adding a line break every time I interrupt the string to insert a variable. Is there a way to prevent this behavior?
Whilst it won’t affect your HTML page at all with the line breaks (unless you are using
preortext-wrap: pre), you should be able to calltrim()on those variables to remove newlines.To find out if your variable has a newline at front or back, try this regex
(I think you have to use single quotes so PHP doesn’t turn your
\ninto a literal newline in the string).