0

Im using this piece of code:

<?php $newstring = preg_replace("/[\n\r]/", "<br />" , $googlemapsbox_text); echo $newstring; ?>

To replace the \n's. What I would like to achieve: limit the amount of <br /> per line, so when preg_replace finds more than 1 \n per line, they ALL should be replaced with ONE <br />.

I hope my question is clear to you, sorry for the weird English

1 Answer 1

2

This should work:

preg_replace("/[\n\r]+/", "<br />", // rest of your code
=====================^ add a + there on your regex
Sign up to request clarification or add additional context in comments.

1 Comment

I did! Thanks a lot for the swift and correct answer! Will accept asap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.