验证 Vimeo 剪辑 url

发布于 2024-08-29 07:11:22 字数 683 浏览 8 评论 0原文

我想验证表单中的字段,以确保它包含链接到 Vimeo 视频的 URL 的正确格式。下面是我在 Javascript 中的内容,但我需要将其转换为 PHP(不是我的强项)

基本上,我需要检查该字段,如果格式不正确,我需要将错误消息存储为变量..如果这是正确的,我将变量存储为空。

// Parse the URL
var PreviewID = jQuery("#customfields-tf-1-tf").val().match(/http:\/\/(www.vimeo|vimeo)\.com(\/|\/clip:)(\d+)(.*?)/);
if ( !PreviewID ) {
    jQuery("#cleaner").html('<div id="vvqvideopreview"><?php echo $this->js_escape( __("Unable to parse preview URL. Please make sure it's the <strong>full</strong> URL and a valid one at that.", 'vipers-video-quicktags') ); ?></div>');
    return;
}

传统的 vimeo 网址如下所示:http://www.vimeo.com/10793773

I'd like to validate a field in a form to make sure it contains the proper formatting for a URL linking to a Vimeo video. Below is what I have in Javascript, but I need to convert this over to PHP (not my forte)

Basically, I need to check the field and if it is incorrectly formatted, I need to store an error message as a variable.. if it is correct, I store the variable empty.

// Parse the URL
var PreviewID = jQuery("#customfields-tf-1-tf").val().match(/http:\/\/(www.vimeo|vimeo)\.com(\/|\/clip:)(\d+)(.*?)/);
if ( !PreviewID ) {
    jQuery("#cleaner").html('<div id="vvqvideopreview"><?php echo $this->js_escape( __("Unable to parse preview URL. Please make sure it's the <strong>full</strong> URL and a valid one at that.", 'vipers-video-quicktags') ); ?></div>');
    return;
}

The traditional vimeo url looks like this: http://www.vimeo.com/10793773

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

已下线请稍等 2024-09-05 07:11:22
if (0 === preg_match('/^http:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $value))
{
    $error = 'Unable to parse preview URL';
}

更新,回复您的评论:

if (0 === preg_match('/^http:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $value, $match))
{
    $error = 'the error';
}
else
{
    $vimeoID = $match[3];
}
if (0 === preg_match('/^http:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $value))
{
    $error = 'Unable to parse preview URL';
}

Update, in reply to your comment:

if (0 === preg_match('/^http:\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $value, $match))
{
    $error = 'the error';
}
else
{
    $vimeoID = $match[3];
}
清引 2024-09-05 07:11:22

只需使用 preg_match 解析您的 $_REQUEST 即可。

$vimeo_array = array();
$vimeo_link = $_REQUEST("form_input_name");
if(preg_match(/http:\/\/(www.vimeo|vimeo)\.com(\/|\/clip:)(\d+)(.*?)/, $vimeo_array, $arr))
{
  $vimeo_code = $vimeo_array[3];
} else {
  $error = "Not a valid link";
}

Just parse your $_REQUEST with preg_match like.

$vimeo_array = array();
$vimeo_link = $_REQUEST("form_input_name");
if(preg_match(/http:\/\/(www.vimeo|vimeo)\.com(\/|\/clip:)(\d+)(.*?)/, $vimeo_array, $arr))
{
  $vimeo_code = $vimeo_array[3];
} else {
  $error = "Not a valid link";
}
友欢 2024-09-05 07:11:22

尝试使用 https / http url

if (preg_match('/^(http|https):\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $vimeo_url, $vimeo_id)){
    $vimeoid = $vimeo_id[4];
}else{
   // error message... 
}

Try this for https / http url

if (preg_match('/^(http|https):\/\/(www\.)?vimeo\.com\/(clip\:)?(\d+).*$/', $vimeo_url, $vimeo_id)){
    $vimeoid = $vimeo_id[4];
}else{
   // error message... 
}
九公里浅绿 2024-09-05 07:11:22

要获取 Vimeo ID 号,您可以执行如下操作:

$link = 'http://vimeo.com/10638288';
if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $link, $match)) {
    $vimeo_id = $match[1];
} else {
    // Show user an error, perhaps
}

我还稍微更改了正则表达式,以保存过多的反斜杠转义字符。

To get at the Vimeo ID number, you could do something like the following:

$link = 'http://vimeo.com/10638288';
if (preg_match('~^http://(?:www\.)?vimeo\.com/(?:clip:)?(\d+)~', $link, $match)) {
    $vimeo_id = $match[1];
} else {
    // Show user an error, perhaps
}

I also slightly altered the regular expression, to save excessive backslash escape characters.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文