本文介绍了如何从asp.net mvc3中的facebook之类的URL中提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法像facebook一样从URL提取数据?

Is there any way to extract data from url like facebook does?

我引用了许多链接,但这是使用php代码.这- http://www.99points.info/2010/07/facebook-like-extracting-url-data-with-jquery-ajax-php/

I refered many links but this is using php code. This- http://www.99points.info/2010/07/facebook-like-extracting-url-data-with-jquery-ajax-php/

http://www.9lessons. info/2010/06/facebook-like-extracting-url-data-with.html

www.webinfopedia.com/extract-meta-data-from-url-using-php.html

www.webinfopedia.com/extract-meta-data-from-url-using-php.html

我想这样实现.我如何在asp.net mvc3应用程序中实现这一点?

I want to implement like this. how can i implement this in my asp.net mvc3 application?

我刚刚引用了这个-www.achari.in/facebook-like-url-data-extract-using-jquery在这种情况下,我不了解他们在php代码中所做的事情,谁能解释这段代码,他们在这方面做了什么?

I just refered this -www.achari.in/facebook-like-url-data-extract-using-jqueryin this i dont understand what they have done in php code,can anyone explain this code, what they have done in this?

在此, 具有index.php文件

In this, index.php file having

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>achari.in - Demo - Facebook Like URL data Extract Using jQuery PHP and Ajax</title>

<link rel="stylesheet" href="css/style.css" type="text/css">
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/jquery.livequery.js"></script>
<script type="text/javascript" src="js/jquery.watermarkinput.js"></script>
</head>
<script type="text/javascript">
    $(document).ready(function(){   
        // delete event
        $('#attach').livequery("click", function(){

            if(!isValidURL($('#url').val()))
            {
                alert('Please enter a valid url.');
                return false;
            }
            else
            {
                $('#load').show();
                $.post("includes/fetch.php?url="+$('#url').val(), {
                }, function(response){
                    $('#loader').html($(response).fadeIn('slow'));
                    $('.images img').hide();
                    $('#load').hide();
                    $('img#1').fadeIn();
                    $('#cur_image').val(1);
                });
            }
        }); 
        // next image
        $('#next').livequery("click", function(){

            var firstimage = $('#cur_image').val();
            $('#cur_image').val(1);
            $('img#'+firstimage).hide();
            if(firstimage <= $('#total_images').val())
            {
                firstimage = parseInt(firstimage)+parseInt(1);
                $('#cur_image').val(firstimage);
                $('img#'+firstimage).show();
            }
        }); 
        // prev image
        $('#prev').livequery("click", function(){

            var firstimage = $('#cur_image').val();

            $('img#'+firstimage).hide();
            if(firstimage>0)
            {
                firstimage = parseInt(firstimage)-parseInt(1);
                $('#cur_image').val(firstimage);
                $('img#'+firstimage).show();
            }

        }); 
        // watermark input fields
        jQuery(function($){

           $("#url").Watermark("http://");
        });
        jQuery(function($){

            $("#url").Watermark("watermark","#369");

        }); 
        function UseData(){
           $.Watermark.HideAll();
           $.Watermark.ShowAll();
        }

    }); 

    function isValidURL(url){
        var RegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;

        if(RegExp.test(url)){
            return true;
        }else{
            return false;
        }
    }

    function confirmQuit()
    {
        var response = confirm('do you wish to close window !');        
        if(response === true)
          {
             return true;
          }
        else {
             return false;
        }
    }
</script>
<body>
<div align="center">
<br clear="all" /><br clear="all" />
<div style="font-size:30px;">Facebook Like URL data Extract Using jQuery PHP and Ajax</div>
<br clear="all" />
<a style="color:#000000; font-size:14px" href="#">Back To Tutorial</a>
<br clear="all" />

<input type="hidden" name="cur_image" id="cur_image" />
<div class="wrap" align="center">

    <div class="box" align="left">

        <div class="head">Link</div>
        <div class="close" align="right">
            <div class="closes" onclick="if(confirmQuit() == true) { window.close(); }"></div>
        </div>

        <br clear="all" /><br clear="all" />

        <input type="text" name="url" size="64" id="url" />
        <input type="button" name="attach" value="Attach" id="attach" />
        <br clear="all" />

        <div id="loader">

            <div align="center" id="load" style="display:none"><img src="images/load.gif" /></div>

        </div>
        <br clear="all" />
    </div>

</div>
</div>
  <br clear="all" />
</body>
</html>

以上代码是ui的一部分

above code is ui part and

    fetch.php
    <?php

   $url = $_REQUEST['url'];
$url = checkValues($url);

function checkValues($value)
{
    $value = trim($value);
    if (get_magic_quotes_gpc()) 
    {
        $value = stripslashes($value);
    }
    $value = strtr($value, array_flip(get_html_translation_table(HTML_ENTITIES)));
    $value = strip_tags($value);
    $value = htmlspecialchars($value);
    return $value;
}   

function fetch_record($path)
{
    $file = fopen($path, "r"); 
    if (!$file)
    {
        exit("Problem occured");
    } 
    $data = '';
    while (!feof($file))
    {
        $data .= fgets($file, 1024);
    }
    return $data;
}

$string = fetch_record($url);


/// fecth title
$title_regex = "/<title>(.+)<\/title>/i";
preg_match_all($title_regex, $string, $title, PREG_PATTERN_ORDER);
$url_title = $title[1];

/// fecth decription
$tags = get_meta_tags($url);

// fetch images
$image_regex = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
preg_match_all($image_regex, $string, $img, PREG_PATTERN_ORDER);
$images_array = $img[1];

?>

    <div class="images">
    <?php
    $k=1;
    for ($i=0;$i<=sizeof($images_array);$i++)
    {
        if(@$images_array[$i])
        {
            if(@getimagesize(@$images_array[$i]))
            {
                list($width, $height, $type, $attr) = getimagesize(@$images_array[$i]);
                if($width >= 50 && $height >= 50 ){

                echo "<img src='".@$images_array[$i]."' width='100' id='".$k."' >";

                $k++;

                }
            }
        }
    }
    ?>
    <!--<img src="ajax.jpg"  alt="" />-->
    <input type="hidden" name="total_images" id="total_images" value="<?php echo --$k?>" />
    </div>
    <div class="info">

        <label class="title">
            <?php  echo @$url_title[0]; ?>
        </label>
        <br clear="all" />
        <label class="url">
            <?php  echo substr($url ,0,35); ?>
        </label>
        <br clear="all" /><br clear="all" />
        <label class="desc">
            <?php  echo @$tags['description']; ?>
        </label>
        <br clear="all" /><br clear="all" />

        <label style="float:left"><img src="images/prev.png" id="prev" alt="" /><img src="images/next.png" id="next" alt="" /></label>

        <label class="totalimg">
            Total <?php echo $k?> images
        </label>
        <br clear="all" />

    </div>

我不了解php,所以有人可以帮助我找到此解决方案吗?

I dont know php so can anybody help me to find this solution?

在上面的代码中,他们使用了此功能

In above code they use this function

   function fetch_record($path)
{
$file = fopen($path, "r"); 
if (!$file)
{
    exit("Problem occured");
} 
$data = '';
while (!feof($file))
{
    $data .= fgets($file, 1024);
}
return $data;
 }

有人可以告诉我这段代码到底是什么打开文件的用途是什么,这是用来读取url索引文件的吗?

can anybody tell me what exactly in this codewhat is use of file open in this, is this for reading url index file??

推荐答案

很遗憾,我之前发布的页面上的链接已死,但现在已修复.

The link on the page I posted before was unfortunately dead but it is fixed now.

http://nalgorithm.wordpress.com/2011/12 /05/embedded-url-representation/

正如我在此处所述,我正在开发此工具的服务版本,以便其他Web应用程序可以仅通过(jquery)和服务调用来使用它.

As I stated there, I am working on the service version of this tool so that other webapps can make use of it just by (jquery) and a service call.

这篇关于如何从asp.net mvc3中的facebook之类的URL中提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 22:17