Log in

View Full Version : PHP not Working...



Agent Moose
12-20-2007, 04:24 PM
I have created a code taht only works on my XAMMP Program, nothing else. I have tried my brothers host that uses PHP, but I get this error:


Fatal error: Cannot redeclare link() in /home/mosthigh/public_html/codeindex2.php on line 4

Here is my code:

<?
echo "<table width='100%' style='font-weight:bold'><tr><td width='33%'>Code</td><td width='33%'>Started By</td><td width='33%'>Views</td></tr></table>";

function link($val){
$as=$val->getElementsByTagName('a');
foreach($as as $a){
return "<a href='".$a->getAttribute('href')."'>".$a->nodeValue."</a>";
}}
$c=1;
for($i=0;$i<$c;$i++){
$doc=new DOMDocument();
@$doc->loadHTMLFile("http://smcodes.smfforfree3.com/index.php/board,8.".($i*15).".html");
$tables=$doc->getElementsByTagName('table');
if($i==0){
$ltds=$doc->getElementsByTagName('td');
foreach($ltds as $ltd){
if($ltd->getAttribute('class')=="middletext" && eregi('go down',$ltd->nodeValue)){
$las=$ltd->getElementsByTagName('a');
foreach($las as $la){
if($la->getAttribute('class')=="navPages"){
$c++;
}}}}}
foreach($tables as $table){
if($table->getAttribute('width')=="100%" && $table->getAttribute('border')=="0" && $table->getAttribute('cellspacing')=="1" && $table->getAttribute('cellpadding')=="4"){
$trs=$table->getElementsByTagName('tr');
foreach($trs as $tr){
$topic=$tr->childNodes->item(4);
$started=$tr->childNodes->item(6);
$view=$tr->childNodes->item(10);
if($topic->nodeValue == "" || $started->nodeValue == "" || $view->nodeValue == ""){
}else if(eregi("When Using My Codes",$topic->nodeValue)){
}else if($topic->nodeValue == "Started by" || $started->nodeValue == "Replies" || $view->nodeValue == "Last post"){
}else{
echo "<table width='100%'><tr><td width='33%'>".link($topic)."</td><td width='33%'>".link($started)."</td><td width='33%'>".$view->nodeValue."</td></table>";
}}}}}
?>

smithster
12-20-2007, 04:31 PM
I think it depends on the PHP version. This script works on my version which is 5.22

Just a tip, not all versions of PHP are happy for scripts to start <?

Think you should try replacing it with <?php

Agent Moose
12-20-2007, 04:42 PM
I just tried adding <?php and it still didn't work.

I believe the hosting I use, the version of the PHP is 3.3.0. At least that is what it says in the PHP configuration setting.

smithster
12-20-2007, 04:46 PM
It is probably too old. Are you running a local server? As in a web server from home?

Why don't you try upgrading your version of PHP at least?

The script you posted, even with the <? tag as you have written it, works from my home server.

Agent Moose
12-20-2007, 04:54 PM
I can't upgrade it. Not the one I am useing on a host. It works fine on my home server.

smithster
12-20-2007, 05:03 PM
Ah I see. I just uploaded the script to my online server which hosts 4.44 and it doesn't actually work there neither. But it does on my home server which hosts 5.22!!

So, either someone else might know what the problem is, or you need to find a host that uses PHP 5 or above.

Sorry there's nothing more I can do for you now!

sfowler
12-20-2007, 08:40 PM
I don't know where, but you'll probably have to find a manual on PHP3.x to find the functions that accomplish the same task. PHP 5.x is a whole lot different than PHP 3.

djr33
12-21-2007, 12:41 AM
The answer is easy.

"Cannot redeclare" means that a function of that name already exists. In PHP you can not ever redefine a function name.

http://www.php.net/manual/en/function.link.php

That is the link function.

Using that name, even if you could, would be confusing.

Find a unique, descriptive name for your functions :)

Agent Moose
12-21-2007, 02:34 AM
Now I am getting this error:

Warning: domdocument() expects at least 1 parameter, 0 given in /home/mosthigh/public_html/codeindex2.php on line 11


<?php
echo "<table width='100%' style='font-weight:bold'><tr><td width='33%'>Code</td><td width='33%'>Started By</td><td width='33%'>Views</td></tr></table>";

function Moosey($val){
$as=$val->getElementsByTagName('a');
foreach($as as $a){
return "<a href='".$a->getAttribute('href')."'>".$a->nodeValue."</a>";
}}
$c=1;
for($i=0;$i<$c;$i++){
$doc=new DOMDocument();
@$doc->loadHTMLFile("http://smcodes.smfforfree3.com/index.php/board,8.".($c*15)."/sort,subject.html");
$tables=$doc->getElementsByTagName('table');
if($i==0){
$ltds=$doc->getElementsByTagName('td');
foreach($ltds as $ltd){
if($ltd->getAttribute('class')=="middletext" && eregi('go down',$ltd->nodeValue)){
$las=$ltd->getElementsByTagName('a');
foreach($las as $la){
if($la->getAttribute('class')=="navPages"){
$c++;
}}}}}
foreach($tables as $table){
if($table->getAttribute('width')=="100%" && $table->getAttribute('border')=="0" && $table->getAttribute('cellspacing')=="1" && $table->getAttribute('cellpadding')=="4"){
$trs=$table->getElementsByTagName('tr');
foreach($trs as $tr){
$topic=$tr->childNodes->item(4);
$started=$tr->childNodes->item(6);
$view=$tr->childNodes->item(10);
if($topic->nodeValue == "" || $started->nodeValue == "" || $view->nodeValue == ""){
}else if(eregi("When Using My Codes",$topic->nodeValue)){
}else if($topic->nodeValue == "Started by" || $started->nodeValue == "Replies" || $view->nodeValue == "Last post"){
}else{
echo "<table width='100%'><tr><td width='33%'>".Moosey($topic)."</td><td width='33%'>".Moosey($started)."</td><td width='33%'>".$view->nodeValue."</td></table>";
}}}}}
?>

djr33
12-21-2007, 12:17 PM
$doc=new DOMDocument();
Well, you need something like:
$doc=new DOMDocument($somethinghere);

But I don't know how to use that. I've never needed it.

Did you write this script yourself? Or did you find it somewhere?

It just seems to have some problems in general. I'm not sure what to suggest.

Agent Moose
12-21-2007, 06:15 PM
Someone created the script for me, then I edited it it some. I didn't change much at all though.