Avatar of befidled
befidled asked on

need help solving preg_match() error

I've got the following method which should be grabbing a youTube video to display on my site but I'm getting a preg_match error. Any idea what might cause this error?
<?php
function youtube($keyword) {
	$url = "http://www.youtube.com/rss/tag/dui.rss";
	$youtube = fopen($url, "r");
	if (preg_match('/<enclosure url=\"(.*)swf/s', $youtube, $y)) {
		$youtube = $y[1];
		$youtube = substr($y[1], 0, 36);
		$video = '';
		$video .= "\n".'<object type="application/x-shockwave-flash" style="width:400px; height:325px;" data="'.$youtube.'">';
    	$video .= "\n".'<param name="movie" value="'.$youtube.'" />';
    	$video .= "\n".'</object>';
    	$video .= "\n";
    	print $video;
    	
	}
}
?>

Open in new window

PHP

Avatar of undefined
Last Comment
mcuk_storm

8/22/2022 - Mon
mcuk_storm

You are treating a file pointer as a string, try this instead:

<?php
function youtube($keyword) {
        $url = "http://www.youtube.com/rss/tag/dui.rss";
        $youtube = implode("\n",file($url));
        if (preg_match('/<enclosure url=\"(.*)swf/s', $youtube, $y)) {
                $youtube = $y[1];
                $youtube = substr($y[1], 0, 36);
                $video = '';
                $video .= "\n".'<object type="application/x-shockwave-flash" style="width:400px; height:325px;" data="'.$youtube.'">';
        $video .= "\n".'<param name="movie" value="'.$youtube.'" />';
        $video .= "\n".'</object>';
        $video .= "\n";
        print $video;
        
        }
}

Open in new window

ASKER CERTIFIED SOLUTION
mcuk_storm

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy