so, first i have this input
$string = "Lorem ipsum
dolor sit amet, consectetur adipiscing
elit https://www.youtube.com/watch?v=example sed do eiusmod tempor incididunt https://www.youtube.com/watch?v=example2 https://www.youtube.com/watch?v=example3";
and then i want to remove the url from the $string
using regex
$string = preg_replace('/[(http(s)?):\/\/(www\.)?a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/', '', $string);
after i removed all of the url from the string, the output will be
Lorem ipsum
dolor sit amet, consectetur adipiscing
elit sed do eiusmod tempor incididunt
the problem is, there is double space and i want to make it more neat
ive tried using this, which will replaced all the double space with single space
$string = preg_replace('/\x20+/', ' ', $string);
and theres come another problem which is theres a space after line break
Lorem ipsum
dolor sit amet, consectetur adipiscing
elit sed do eiusmod tempor incididunt
and it makes me uncomfortable.
i need a solution to get rid of the url, but also makes it neat. the last result I want is like this
Lorem ipsum
dolor sit amet, consectetur adipiscing
elit sed do eiusmod tempor incididunt
sorry if its looks weird, thanks