Display original text, with broken lines, inside the tag a

1

I'm trying to put a text with more than one paragraph as a link, but the display inside the tag % with% removes any line breaks that are in the text. I'm doing the following:

<a style="cursor: pointer;" onclick="wpquery_link_filter(' <?= preg_replace('/\s+/', ' ', $value) ?> ', <?= $property['id'] ?>)">
    <?= $value ?>
</a>

I'm getting something like this:

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer without magna, eleifend id hendrerit vel, imperdiet sit amet ligula. Cras eleifend quam vel ex fringilla fringilla. Phasellus at nibh eget lorem ullamcorper faucibus tristique eu purus. Donec wanted door turpis, posuere mauris wanted, urn elementum. Nunc maximus neque feugiat, eros erges egestas, fair varius. Proin accumsan fringilla sapien ut varius. Cras non finibus nisi, eu pretium lacus. Pellentesque elementum maximus erat ut posuere. Vivamus elementum mauris et nisl ullamcorper, wanted suscipit ipsum tempor. Proin sit amet pain quam. Cras mattis malesuada dui. Morbi ac mass to hate facilisis vehicula. Sed a diam sed nisl egestas fermentum. Class aptent taciti partnersqu ad litora torquent per conubia nostra, per hisceptions himenaeos. Vestibulum varius nec nibh at hendrerit. Quisque augue urna, lobortis ut cursus sed, bibendum sed orci. Donec maximus, erat ut elementum porttitor, erat elit fringilla enim, at imperdiet odio urna nec lorem. Orci varius natoque penatibus et magnis dis parturient mounts, nascetur ridiculus mus. Ut vitae without dignissim, consequat metus non, vehicula augue. Donec wanted nisl sit amet erat auctor tempus. Proin at sollicitudin turpis, sit amet vestibulum leo. Nunc tellus erat, consectetur a posuere non, aliquet id sem.

How can I make the display remain as the original text?

    
asked by anonymous 18.08.2017 / 14:38

1 answer

2

The problem occurs that the line breaks in the text are not rendered as line breaks in the html, so the <br> tag exists. What you need to do is to convert the line breaks from the $value variable to the <br> tag.

Since the text comes from a PHP variable, the native function nl2br does exactly that. You check the documentation for this function here , and your code with the function just below it:

<a style="cursor: pointer;" onclick="wpquery_link_filter(' <?= preg_replace('/\s+/', ' ', $value) ?> ', <?= $property['id'] ?>)">
    <?= nl2br($value) ?>
</a>
    
18.08.2017 / 14:49