(Simplified) code from a WordPress project:
function fix_youtube_links ($content) {
$append = '&w=480&rel=0';
$content = preg_replace('/^http:\/\/(?:www\.)?(?:youtube.com\/(?:v\/|watch[\/\#?])|(youtu\.be\/)).*/im', '$0'.$append, $content);
return $content;
}
add_filter('the_content', 'fix_youtube_links');
$content looks something like this:
blah blah blah
blah blah blah
And I want to add $append to the matches and get this:
blah blah blah
blah blah blah
But instead I am getting this:
blah blah blah
&w=480&rel=0
blah blah blah
…because the end-of-line is being included in the match.
Any suggestions? Regex or non-regex solutions welcomed.
Try this one: