hello i have laravel blade and here is the part that have the issue
@php
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
@endphp
<div class="message">
@php
$text = nl2br(e($message));
@endphp
@if(preg_match($reg_exUrl, $text, $url)){!! preg_replace($reg_exUrl, '<a href="$0" target="_blank">$0</a> ', $text) !!}
@else {!!$text!!}
@endif
</div>
this works good if the link is only in the text but if it got mixed with some words and some break line like this message
hello dear buyer
the link is working good https://google.com/blabla
and some random text
it converted to this html code
hello dear buyer<br>
<br>
the link is working good<br>
<a href="https://google.com/blabla<br" target="_blank">https://google.com/blabla<br< a=""> />
<br>
and some random text<br>
<br>
how to fix this
i want to replace the url into anchor tag and show the break line if the user enters message contains lines
also to use the e() function in blade to prevent any html code from running
any one help please
Hmm, your code just works if there is only a space before the <br> tag. I don't think you can do this since the
is tied to link. Maybe you can do this for now (until someone else has a better solution) and make sure the e() is called after the str_replace:
$message = str_replace('<br>', ' <br>', $message);
// Optional to trim double spaces
$message = preg_replace('/\s\s+/', ' ', $message);