Please help with pre_match! Please

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
hawkeyes
Forum Newbie
Posts: 2
Joined: Sun Sep 02, 2007 11:26 am

Please help with pre_match! Please

Post by hawkeyes »

Hello all;

I want to embedded videos from some website, so i made this code

Code: Select all

if (preg_match("/http:\/\/youtube.com\/watch\?v=([0-9a-zA-Z-_-]*)(.*)/i", $url, $matches)) {
        return '<object width="425" height="350">'.
               '<param name="movie" value="http://www.youtube.com/v/'.$matches[1].'" />'.
               '<param name="wmode" value="transparent" />'.
               '<embed src="http://www.youtube.com/v/'.$matches[1].'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350" />'.
It works perfectly; but now i one website with the link have "," (like http://www.something.com/watch/yod,cn,hello-world-.html )

and their embedded code like this:

Code: Select all

<object width="448" height="372"><param name="movie" value="http://www.something.com/w/yod,cn,0"/><param name="allowFullScreen" value="true"/><embed src="http://www.something.com/w/yod,cn,0" type="application/x-shockwave-flash" allowFullScreen="true" width="448" height="372"></embed></object>

But i tried the same code with youtube up there, ti doesnt work, it said their some invalid characters; and i know that is because of "," character in the link and may be because of the link to the file and the link in embeded so different too ...

So how i get rid of that thing then i can embedded them like youtube?

Please help,

Thank you for your time
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

You have to escape the comma, I'm guessing.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
josa
Forum Commoner
Posts: 75
Joined: Mon Jun 24, 2002 4:58 am
Location: Sweden

Post by josa »

I don't see anything wrong with the code in your post, except that you have to modify the regex to make it work as you expect. The error must come from somewhere else. If you post the modified code then someone might be able to help you.

/josa
hawkeyes
Forum Newbie
Posts: 2
Joined: Sun Sep 02, 2007 11:26 am

Post by hawkeyes »

hello;

I'm using the same code with the youtube (which wokrs perfectly); but because of the "," thing thats why made the error...so i do not know how to pre_match the "," thing?

Thank you for reply
Post Reply