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
Post a Comment