|
-
Jun 14th, 2009, 03:39 PM
#1
Thread Starter
Hyperactive Member
[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($fp, 4096);
}
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
-
Jun 14th, 2009, 05:05 PM
#2
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.\
-
Jun 14th, 2009, 05:10 PM
#3
Thread Starter
Hyperactive Member
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
-
Jun 14th, 2009, 07:19 PM
#4
Re: Strange META tag issue
PHP Code:
$text_line[] = trim(fgets($fp, 4096));
-
Jun 15th, 2009, 06:25 AM
#5
Thread Starter
Hyperactive Member
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
-
Jun 15th, 2009, 01:22 PM
#6
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.
-
Jun 15th, 2009, 03:37 PM
#7
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($array, 6, ""); //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" />
-
Jun 15th, 2009, 05:32 PM
#8
Thread Starter
Hyperactive Member
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($fp, 4096)); } 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.
-
Jun 15th, 2009, 05:43 PM
#9
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.
-
Jun 15th, 2009, 06:05 PM
#10
Thread Starter
Hyperactive Member
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!
-
Jun 15th, 2009, 06:21 PM
#11
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|