www.webdeveloper.com
Results 1 to 5 of 5

Thread: Printing array values | Meta Tag Analyzer

Threaded View

  1. #1
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,114

    Printing array values | Meta Tag Analyzer

    I have an array that I would like to print out.

    I have a test form up here that will analyze a given site's meta tags. I would like to simply get the meta-tags, and then list them or put them into a table...

    So far, here is what I have:
    http://metataggenerator.org/analyzer/

    You can enter an URL into the box and the script will print out the meta tags in a list or table.

    The code thus far:
    PHP Code:
    <!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=utf-8" />
    <title>Meta Tag Analyzer</title>

    </head>

    <body>
    <form action="test.php" method="post">
    <input type="text" name="url"  onFocus="this.value=''; this.onfocus=null;" onblur="this.value='Enter your URL here';" value="Enter your URL here" />
    <input type="submit" value="Analyze Meta Tags" />
    </form><br />
    <?php
    $url 
    $_POST['url'];
    $url str_replace("Enter your URL here"''$url);  //makes sure that there is an URL
    if ($url == '' ) {
        echo  
    "Enter an URL to analyze above";
        echo 
    "\n";
    } else {
        
    $url "http://$url";                         // adds http:// to the URL in case the user forgets it...
    $url preg_replace('[http://http://]''http://'$url);     // makes the form work with or without the http:// by simply removing double http://http://
    function getUrlData($url)
    {    
        
    $result false;     
        
    $contents getUrlContents($url);     
        if (isset(
    $contents) && is_string($contents))    
        {        
            
    $title null;        
            
    $metaTags null;         
            
    preg_match('/<title>([^>]*)<\/title>/si'$contents$match );         

            if (isset(
    $match) && is_array($match) && count($match) > 0)        
            {            
                
    $title strip_tags($match[1]);        
            }         

            
    preg_match_all('/<[\s]*meta[\s]*name="?' '([^>"]*)"?[\s]*' 'content="?([^>"]*)"?[\s]*[\/]?[\s]*>/si'$contents$match);         
            if (isset(
    $match) && is_array($match) && count($match) == 3)        
            {            
            
    $originals $match[0];            
            
    $names $match[1];            
            
    $values $match[2];             
            if (
    count($originals) == count($names) && count($names) == count($values))            
            {                
            
    $metaTags = array();                 
            for (
    $i=0$limiti=count($names); $i $limiti$i++)                
            {                    
            
    $metaTags[$names[$i]] = array (                        
                
    'html' => htmlentities($originals[$i]),                        
                
    'value' => $values[$i]                    
                );                
            }            
           }        
          }         

    $result = array (            
        
    'title' => $title,            
        
    'metaTags' => $metaTags        
        
    );    
      }     
    return 
    $result;
    } function 
    getUrlContents($url$maximumRedirections null$currentRedirection 0)
    {    
    $result false;     
    $contents = @file_get_contents($url);     // Check if we need to go somewhere else     
    if (isset($contents) && is_string($contents))    
    {        
    preg_match_all('/<[\s]*meta[\s]*http-equiv="?REFRESH"?' '[\s]*content="?[0-9]*;[\s]*URL[\s]*=[\s]*([^>"]*)"?' '[\s]*[\/]?[\s]*>/si'$contents$match);        
    if (isset(
    $match) && is_array($match) && count($match) == && count($match[1]) == 1)        
    {            
    if (!isset(
    $maximumRedirections) || $currentRedirection $maximumRedirections)            
    {                
    return 
    getUrlContents($match[1][0], $maximumRedirections, ++$currentRedirection);
                }            
     
    $result false;        
    }        else        
    {            
    $result $contents;        
    }    
    }     
    return 
    $contents;

    $result getUrlData("$url"); 
    echo 
    '<hr />';
    echo 
    '<h1>Results</h1>';
    echo 
    "<b>Results for:</b> ";
    echo 
    '<font color="red" face="courier">';
    echo 
    $url;
    echo 
    '</font>';
    echo 
    '<br />';
    echo 
    "&lt;title&gt;";
    echo 
    $result[title];
    echo 
    '&lt;/title&gt;';
    echo 
    '<br /><font size="-1">';
    echo 
    $result[metaTags][description][html]; 
    echo 
    '<br />';
    echo 
    $result[metaTags][keywords][html]; 
    echo 
    '<br />';
    echo 
    $result[metaTags][Charset][html]; 
    echo 
    '<br />';
    echo 
    '<font color="red" face="arial">&uarr; <i>This is what I would like the results page to look like, except with the full listing of all metatags on the page</i></font>';
    echo 
    '<hr />';
    echo 
    'Here is a listing of the types of tags that appear on the page, but I cannot figure out how to extract the HTML array and display it...';

    // start table and print heading
    reset($result[metaTags]);
    list(
    $c1$c2) = each($result[metaTags]);
    echo(
    "<table><tr><td>$c1</td><td>$c2</td></tr>\n");
    // print the rest of the values
    while (list($c1,$c2) = each($result[metaTags])) {
      echo(
    "<tr><td>$c1</td><td>$c2</td></tr>\n");
    }
    // end the table
    echo("</table>");
    //end test


    echo '<hr />';

    echo 
    '</font>';
    /////////////////
    echo '<pre>'
    print_r($result[metaTags]); 
    echo 
    '</pre>';
    }

    ?>
    </body>
    </html>
    Last edited by donatello; 05-27-2011 at 11:46 AM.
    [URL="http://www.metataggenerator.org"][SIGPIC][/SIGPIC][/URL]

    Privacy Policy Generator

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17743 seconds
  • Memory Usage 3,321KB
  • Queries Executed 14 (?)
More Information
Template Usage (31):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (2)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)showthread_list
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (27):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./includes/functions_threadedmode.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (74):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids_threaded
  • showthread_threaded_construct_link
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • bbcode_parse_start
  • postbit_imicons
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates