Trying to run some PHP on a HTML site not working

Discussion in 'PHP' started by goy, Oct 9, 2010.

  1. #1
    I am trying to run a small code to replace the keyword but it is not working.

    I did this already

    http://php.about.com/od/advancedphp/p/html_php.htm

    <?php
    /* 
    ** Extracts and formats meta tag content 
    */ 
    
    function get_meta_data($url, $searchkey='') {    
        $data = get_meta_tags($url);    // get the meta data in an array 
        foreach($data as $key => $value) { 
            if(mb_detect_encoding($value, 'UTF-8, ISO-8859-1', true) != 'ISO-8859-1') {    // check whether the content is UTF-8 or ISO-8859-1 
                $value = utf8_decode($value);    // if UTF-8 decode it 
            } 
            $value = strtr($value, get_html_translation_table(HTML_ENTITIES));    // mask the content 
            if($searchkey != '') {    // if only one meta tag is in demand e.g. 'description' 
                if($key == $searchkey) { 
                    $str = $value;    // just return the value 
                } 
            } else {    // all meta tags 
                $pattern = '/ |,/i';    // ' ' or ',' 
                $array = preg_split($pattern, $value, -1, PREG_SPLIT_NO_EMPTY);    // split it in an array, so we have the count of words            
                $str .= '<p><span style="display:block;color:#000000;font-weight:bold;">' . $key . ' <span style="font-weight:normal;">(' . count($array) . ' words | ' . strlen($value) . ' chars)</span></span>' . $value . '</p>';    // format data with count of words and chars 
            } 
        } 
        return $str; 
    } 
    
    $urlpage = "http://www.example.com";
    $urlpage = $urlpage.$_SERVER["PHP_SELF"];
    //echo $urlpage;
    //echo "<br /><br />";
    
    //$content .= get_meta_data($urlpage); 
    /* 
    output looks like this: 
    
    description (23 words | 167 chars) 
    SELFHTML 8.1.2 - Die bekannte Dokumentation zu HTML, JavaScript und CGI/Perl - Tutorial und Referenz, mit etlichen Zusatztips zu Design, Grafik, Projektverwaltung usw. 
    
    keywords (13 words | 119 chars) 
    SELFHTML, HTML, Dynamic HTML, JavaScript, CGI, Perl, Grafik, WWW-Seiten, Web-Seiten, Hilfe, Dokumentation, Beschreibung 
    
    etc. 
    
    */ 
    
    $content = get_meta_data($urlpage, "description"); 
    //$content .= get_meta_data($urlpage, "description"); 
    //echo $content;
    /* 
    output looks like this: 
    
    SELFHTML 8.1.2 - Die bekannte Dokumentation zu HTML, JavaScript und CGI/Perl - Tutorial und Referenz, mit etlichen Zusatztips zu Design, Grafik, Projektverwaltung usw. 
    */ 
    ?>
    PHP:
     
    goy, Oct 9, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Did you try :
    
    AddHandler application/x-httpd-php .html .htm 
    
    PHP:
    ..and or for php 5

    
    AddHandler application/x-httpd-php5 .html .htm 
    
    PHP:
     
    MyVodaFone, Oct 9, 2010 IP
  3. goy

    goy Well-Known Member

    Messages:
    1,010
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #3
    yes thanks i did i must made some mistake in my code i do not know really whats the problem.
     
    goy, Oct 9, 2010 IP