Solved

Need help building this class  to get id from url using preg_match

Posted on 2014-04-17
8
394 Views
Last Modified: 2014-04-18
building php class

Need help building this class to retrieve the id of the video.

the url is :  http://www.dailymotion.com/video/xsr67x

public function dailymotion($url, $w="400", $h="250") {
              if (preg_match('((http://|https://|www.)+(dailymotion.)[\w-\d]+(video)+(/)+(\d+))',$url, $id)){
              $id=$id[5];
                  return  $id ;
                }
      }

Please advise...
0
Comment
Question by:morako
8 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 40008011
Given this for the input:

http://www.dailymotion.com/video/xsr67x

What do you want to get for the output?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40008079
Why not simply:

$id = substr($url, strrpos($url, "/"))
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 40008236
@kaufmed: I think the OP wants to make sure the link is from dailymotion.

This should match:
public function dailymotion($url, $w="400", $h="250") {
              if (preg_match('%(?:http://|https://)(?:www\.)?dailymotion\.com.*?video/(\w+)%',$url, $id)){
              $id=$id[1];
                  return  $id ;
                }
      }

Open in new window

HTH,
Dan
0
 

Author Closing Comment

by:morako
ID: 40008361
Perfect,  Thank you...  ;-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 34

Expert Comment

by:Dan Craciun
ID: 40008367
You're welcome. Glad I could help!
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40008583
I think the OP wants to make sure the link is from dailymotion

I still think regex is overkill for that...

if (strpos($url, "dailymotion.com"))
{
    $id = substr($url, strrpos($url, "/"));
{

Open in new window

0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 40008593
You're probably right, but a regex will give a correct result on this:

http://www.dailymotion.com/video/xsr67x/

whereas strrpos will not.
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 40008652
I'll spare you the simple change that would account for that variation   ; )
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Please show me easiest post form. 3 31
phpmyadmin 3 32
xampp tool 12 24
array_values - reorder after unset? 5 11
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now