string - PHP preg_replace not replacing anything -


can tell me why when run code preg_replace function seems nothing?

<?php     $string     = 'waka http://video.webmfiles.org/big-buck-bunny_trailer.webm waka';     $search     = '#http\:\/\/.\.webm #';     $replace    = '<video width="320" height="240" controls><source src="$1" type="video/webm"></video>';     $url = preg_replace($search,$replace,$string);     echo $url; ?> 

is $search string wrong? if so, how can fix it? it's suppose replace strings starting in http:// , ending in .webm , surround them html code needed play .webm video.

here's how i'd this...

$string     = 'waka http://video.webmfiles.org/big-buck-bunny_trailer.webm waka'; $search     = '/(https?\:\/\/.+?\.webm)\h/'; $replace    = '<video width="320" height="240" controls><source src="$1" type="video/webm"></video> '; $url = preg_replace($search,$replace,$string); echo $url; 

output:

waka <video width="320" height="240" controls><source src="http://video.webmfiles.org/big-buck-bunny_trailer.webm" type="video/webm"></video> waka 

regex101 demo: https://regex101.com/r/qr1xj7/2


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -