post - PHP: Add video tag to youtube link fron content -


i have variable $post->post_content return me detail of post , video url youtube.

i need remove text $post->post_content else youtube link, , add youtube likn tag

<video>youtube_url</video> 

the content :-

at instant, while daggoo, on summit of head, clearing whip—which had somehow got foul of great cutting tackles—a sharp cracking noise heard; , unspeakable horror of all, 1 of 2 enormous hooks suspending head tore out, , vast vibration enormous mass sideways swung, till drunk ship reeled , shook if smitten iceberg. 1 remaining hook, upon entire strain depended, seemed every instant on point of giving way; event still more violent motions of head.  https://www.youtube.com/watch?v=jerem0zky18 

and time :-

أسر شعار اسبوعين الدولارات من, شرسة أعلنت اندلاع إذ هذا. وبعد الثالث أوكيناوا ما بين, الحصار الأمامية بـ عدد. ذات بقعة فمرّ إذ, أخذ كل بالحرب وسمّيت المانيا. و فصل بمباركة المقيتة, أملاً الحصار المتاخمة من عدد. بزمام أثره، التبرعات تم بعد, الجيش خصوصا كانتا ان دار.      https://www.youtube.com/watch?v=jerem0zky18 

my code:

$posts = query_posts('showposts='.$numposts.'&cat=19'); foreach ($posts $post) {  $postoutput1 = preg_replace('#<a[^>]+>([\r\n|\n]+)?<img[^>]+>([\r\n|\n]+)?<\/a>#','', $post->post_content); $postoutput2 = preg_replace('@https?://(www\.)?youtube.com/.[^\s.,"\']+@i','', $postoutput1); $postoutput = preg_replace('[youtube','', $postoutput2); preg_match_all('@https?://(www\.)?youtube.com/.[^\s.,"\']+@i', $post->post_content, $matches); foreach($matches $match){     echo "<video>$match</video>"; }} 

how can that.?

try this:

$string = "at instan ... https://www.youtube.com/watch?v=jerem0zky18" $pattern = '/(http\s*)/im'; $array = array(); preg_match($pattern, $string, $array); $link = $array[0]; print $link; 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - How to Hide Date Menu from Datepicker in yii2 -