By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
461,998 Members | 494 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 461,998 IT Pros & Developers. It's quick & easy.

Having trouble use "While"

Ajm113
100+
P: 161
Ok I got my stuff to split, but how can I have the while work correctly so it will show all of the arrays correctly? Like if you where using Mysql to retrieve data. But this time it is retrieving all the page meta tags and displaying them in a list.

Here is my own Meta Tag I made that I am using for the script:
Expand|Select|Wrap|Line Numbers
  1. <META NAME="pages" CONTENT="Web Developer;http://www.bombinaid.com/Web-Developer">
Here is the script where I want all my page's meta tag to show in a list.

[PHP] $pages = $tags['pages'];
$pieces = explode(";", $pages);

$title = $pieces['0'];
$url2 = $pieces['1'];
while(each($pieces))
{
echo "<a href=\"";
echo $url2;
echo"\">";
echo $title;
echo"</a><br>";
}
[/PHP]
Thanks, Ajm113.
Aug 13 '07 #1
Share this Question
Share on Google+
15 Replies

pbmods
Expert 5K+
P: 5,821
Heya, AJM.

What do you want your code to do? Give an example.
What is your code doing that you don't want it to do? Give an example.
What is your code *not* doing that it is supposed to? Give an example.
Aug 13 '07 #2

Ajm113
100+
P: 161
I want my code to get all the meta tags that have the word "page" in the name area of the meta tag then retrieve the content field and separate the two areas that have a ";" in it then echo out the two areas so it will show in a url. So the user may click on it for the user to goto another page the site shows.

In the users website:
<meta name="page" content="Downloads;http://www.domain123.com/Downloads">
<meta name="page" content="Contact Us;http://www.domain123.com/Contact_Us">

Echo on my page using the while script that are made so it will echo the number of page meta tags and display them like so:

<a href="http://www.domain123.com/Downloads">Downloads</a>

<a href="http://www.domain123.com/Contact_Us">Contact Us</a>

Right now when I do have more then one page meta tag the script is echoing the second page meta tag two times and not showing the first one.

Here it is on action with the bug:
http://www.bombinaid.com/search.php?...binaid&orgin=1

Just click on the question mark after the url of my website on the results area.
Then look under Redirect Links in the popup window.
Aug 13 '07 #3

Atli
Expert 5K+
P: 5,058
You should consider using the foreach loop.

Like so:
Expand|Select|Wrap|Line Numbers
  1. $pages = explode(";", $tags['pages']);
  2. foreach($pages as $page) {
  3.   $pieces = explode(",", $page);
  4.   echo '<a href="'. $pieces[0] .'">"'. $pieces[1] .'"</a><br />';
  5. }
  6.  
Aug 13 '07 #4

Ajm113
100+
P: 161
Now all its doing is just showing two links with "" in them and I even added another pages meta tag to find a solution or problem, but it is still doing the same thing.

And yes I did take a look at the link, but it does not seem to help me.
Aug 14 '07 #5

pbmods
Expert 5K+
P: 5,821
Heya, AJM.

Neat idea.

Ok. Starting from basics.

If a User's page has this in the head element:
Expand|Select|Wrap|Line Numbers
  1. <meta name="page" content="Downloads;http://www.domain123.com/Downloads">
  2. <meta name="page" content="Contact Us;http://www.domain123.com/Contact_Us">
  3.  
Are you saying that your script outputs this:
Expand|Select|Wrap|Line Numbers
  1. <a href="http://www.domain123.com/Contact_Us">Contact Us</a>
  2. <a href="http://www.domain123.com/Contact_Us">Contact Us</a>
  3.  
Perhaps the problem is outside the code snippet that you provided. Let's see where you calculate $tags['pages'].
Aug 14 '07 #6

Ajm113
100+
P: 161
[PHP]$GetSite = $_GET['url'];


$tags = get_meta_tags($GetSite);

$author = $tags['author'];
$level = $tags['level'];
$description = $tags['description'];
$keywords = $tags['keywords'];


$fp = fopen( $GetSite, 'r' );

$content = "";


while( !feof( $fp ) ) {

$buffer = trim( fgets( $fp, 4096 ) );
$content .= $buffer;

}

$start = '<title>';
$end = '<\/title>';

preg_match( "/$start(.*)$end/s", $content, $match );
$title = $match[ 1 ];
[/PHP]

Thats about it right their for the exeption of where it echos the table with the content in the other meta tags.
Aug 14 '07 #7

pbmods
Expert 5K+
P: 5,821
Heya, AJM.

Very nice.

And what does get_meta_tags() look like?
Aug 14 '07 #8

Ajm113
100+
P: 161
Look here on this page for more information about that command.
Aug 14 '07 #9

pbmods
Expert 5K+
P: 5,821
Wow. Somebody actually made ME go RTFM!

hah. Well look at that.

Ok, What does this look like:
Expand|Select|Wrap|Line Numbers
  1. print_r($tags['pages']);
  2.  
Aug 14 '07 #10

Ajm113
100+
P: 161
It looks like this to me.
[PHP]print_r($tags['pages']);[/PHP]

Just kidding, it renders out like this:
Submit A Site;http://www.bombinaid.com/tellme.php
Aug 14 '07 #11

pbmods
Expert 5K+
P: 5,821
Oh, ha ha.

How about a page that has multiple 'Page' meta tags? Humor me here; what is the output of print_r()?
Aug 14 '07 #12

Ajm113
100+
P: 161
Submit A Site;http://www.bombinaid.com/tellme.php
It shows up like that.
Aug 14 '07 #13

pbmods
Expert 5K+
P: 5,821
Interesting. So the get_meta_tags() function is not returning the proper values then?
Aug 14 '07 #14

Atli
Expert 5K+
P: 5,058
Is it possible that only one Meta tag named 'pages' can exist, so only the last one is available in the PHP script?
Aug 14 '07 #15

Ajm113
100+
P: 161
Yep, the source code of my home page says it all if you taken the time to look at the link and goto my site's result on that link I posted and clicked the question mark to see what it displays then.

Look at my site and open the source code in your browser and look under the meta tag area I have in their.
Aug 15 '07 #16

Post your reply

Sign in to post your reply or Sign up for a free account.