Results 1 to 11 of 11

Thread: [RESOLVED] Strange META tag issue

  1. #1

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Resolved [RESOLVED] Strange META tag issue

    Hi all,

    Just wondering if anyone can shed some light on the following issue for me.

    I'm pulling in a websites title, description and keywords using the following code:

    PHP Code:
    <?php
    //open meta file
    $this_page "home";
    $text_file "meta/".$this_page.".txt";
    $fp = @fopen($text_file"r");
    $text_line = array();
    while(!(
    feof($fp)))
    {
        
    $text_line[] = fgets($fp4096);
    }
    for (
    $i=count($text_line);$i<6;$i++)
    {
        
    $text_line[] = '';
    }
    fclose($fp);
    ?>
    <!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>
    <title><?php echo $text_line[1];?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="description" content="<?php echo $text_line[2];?>" />  
    <meta name="keywords" content="<?php echo $text_line[3];?>" />
    <link href="css/default.css" rel="stylesheet" type="text/css" />
    Now the problem I have is that when the content is populated the source code view looks like this:

    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>
    <
    title>some text here
    </title>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    meta name="description" content="some text here. 
    />  
    <
    meta name="keywords" content=", ivr, sms, text, voicexml ivr, ivr hosting, ivr platform, ivr server, ivr applications, interactive voice response, ivr,  sms
    />
    <
    link href="css/default.css" rel="stylesheet" type="text/css" /> 
    So for some reason after the last line of text it is moving the end tag instead of it being after the last line of text. Can anyone please tell me why this is occuring and how to possibly fix it so the end tags are after the last piece of text.

    Many thanks

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Strange META tag issue

    The line break at the end of the line is included when you use fgets. Use the trim() function to remove any leaidng or trailing line breaks and whitespace.\
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Strange META tag issue

    Hi,

    Thank you so much for that; however, I'm at a loss as to how to add the code you have suggested.

    Could you possibly show me?

    Many thanks

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Strange META tag issue

    PHP Code:
    $text_line[] = trim(fgets($fp4096)); 

  5. #5

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Strange META tag issue

    Hi,

    When I use the trim() in the line of code it is preventing the page links from working. That is each time I click on a page link it doesn't do anything and remains on the INDEX page.

    Any thoughts on why and how to possibly amend this. I have removed the trim() function and the page links work fine.

    Many thanks

  6. #6
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: Strange META tag issue

    Could you perhaps post the resultant source code with the faulty links after you've used trim()? There should be no such effect on links from the trim() function, so I'd wager something else is the culprit here.

  7. #7
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: Strange META tag issue

    I rewrote what you might want to do in a little more efficient way:
    PHP Code:
    <?php
      
    //your meta tag file
      
    $str file_get_contents($filename);

      
    //create your array
      
    $array explode("\n"$str);       //split $str by line breaks
      
    array_walk($array"utrim");        //trim every element
      
    $array array_pad($array6"");  //pad the array up to 6 values

      //php won't use array_walk() with its own functions, so we use this
      
    function utrim(&$value$key){
        
    $value trim($value);
      }
    ?>
    <!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>
    <title><?php echo $array[1]; ?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="description" content="<?php echo $array[2]; ?>" />  
    <meta name="keywords" content="<?php echo $array[3]; ?>" />
    <link href="css/default.css" rel="stylesheet" type="text/css" />
    this produced the following, with a test file:
    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>
    <title>some text here</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="description" content="some text here." />  
    <meta name="keywords" content=", ivr, sms, text, voicexml ivr, ivr hosting, ivr platform, ivr server, ivr applications, interactive voice response, ivr,  sms" />
    <link href="css/default.css" rel="stylesheet" type="text/css" />

  8. #8

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Strange META tag issue

    Hi,

    I have tried the above; however, I'm still getting errors.

    Below is the code in full:

    PHP Code:
    <?php 
    //open meta file 
    $this_page "home"
    $text_file "meta/".$this_page.".txt"
    $fp = @fopen($text_file"r"); 
    $text_line = array(); 
    while(!(
    feof($fp))) 

        
    $text_line[] = trim(fgets($fp4096)); 

    for (
    $i=count($text_line);$i<6;$i++) 

        
    $text_line[] = ''

    fclose($fp); 
    ?> 
    <!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>
    <title><?php echo $text_line[0];?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta name="description" content="<?php echo $text_line[2];?>" />  
    <meta name="keywords" content="<?php echo $text_line[1];?>" />
    <link href="css/default.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
    <link href="css/ie.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    </head>
    <body>
    Last edited by Olly79; Jun 15th, 2009 at 06:21 PM.

  9. #9
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906

    Re: Strange META tag issue

    Posts like that are a waste of time. If you want help, then please make an effort to help yourself. You can start by posting the HTML code as requested above.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Strange META tag issue

    I had cut-and-paste the wrong information; therefore I had simply written error (as in posted in error) until I had pasted the correct message!

  11. #11

    Thread Starter
    Hyperactive Member Olly79's Avatar
    Join Date
    May 2005
    Posts
    264

    Re: Strange META tag issue

    Found the issue...there has been an overwrite on the $this_page = ""; thus the reason why the links were not working!!!

    Thanks to everyone for the assistance - much appreciated.

Posting Permissions

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



Click Here to Expand Forum to Full Width