<?php $string = "youtube1234\r\nyoutube4567"; $string = nl2br(preg_replace('/youtube(\S*)/', '<iframe src="https://w...content-available-to-author-only...e.com/embed/$1"></iframe>', $string)); echo $string;
Standard input is empty
<iframe src="https://w...content-available-to-author-only...e.com/embed/1234"></iframe><br /> <iframe src="https://w...content-available-to-author-only...e.com/embed/4567"></iframe>