Calificación:
  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
Problemas Con Funcion en PHP
#1
Triste 
Buenas Noches Chicos Soy un novato en Esto del PHP y sus Script tengo el siguiente Problema a ver si me Pueden ayudar

1. Me sale el Siguiente Error en mis Log.
([16-Oct-2011 00:35:26] PHP Warning: Invalid argument supplied for foreach() in /home/xester11/public_html/prueba/demo/playing.php on line 262)

2. este es mi Codigo del Script
Código PHP:
<?php
header
("Content-Type: text/html");
// URL to your Shoutcast server, including port
// don't put in the http:// part!  do it like you see here
// also, reverse DNS lookup needs to be on, or this probably won't work
$server "IP:PORT";
// Admin password for your Shoutcast server
$password "Undefined";
$countries = array (
"ac" => "Ascension Island",
"ad" => "Andorra",
"ae" => "United Arab Emirates",
"af" => "Afghanistan",
"ag" => "Antigua and Barbuda",
"ai" => "Anguilla",
"al" => "Albania",
"am" => "Armenia",
"an" => "Netherlands Antilles",
"ao" => "Angola",
"aq" => "Antarctica",
"ar" => "Argentina",
"as" => "American Samoa",
"at" => "Austria",
"au" => "Australia",
"aw" => "Aruba",
"ax" => "Ã…land",
"az" => "Azerbaijan",
"ba" => "Bosnia and Herzegovina",
"bb" => "Barbados",
"bd" => "Bangladesh",
"be" => "Belgium",
"bf" => "Burkina Faso",
"bg" => "Bulgaria",
"bh" => "Bahrain",
"bi" => "Burundi",
"bj" => "Benin",
"bm" => "Bermuda",
"bn" => "Brunei Darussalam",
"bo" => "Bolivia",
"br" => "Brazil",
"bs" => "Bahamas",
"bt" => "Bhutan",
"bw" => "Botswana",
"by" => "Belarus",
"bz" => "Belize",
"ca" => "Canada",
"cd" => "Democratic Republic of the Congo",
"cf" => "Central African Republic",
"cg" => "Republic of the Congo",
"ch" => "Switzerland",
"ci" => "Côte d'Ivoire",
"ck" => "Cook Islands",
"cl" => "Chile",
"cm" => "Cameroon",
"cn" => "People's Republic of China",
"co" => "Colombia",
"cr" => "Costa Rica",
"cu" => "Cuba",
"cv" => "Cape Verde",
"cx" => "Christmas Island",
"cy" => "Cyprus",
"cz" => "Czech Republic",
"de" => "Germany",
"dj" => "Djibouti",
"dk" => "Denmark",
"dm" => "Dominica",
"do" => "Dominican Republic",
"dz" => "Algeria",
"ec" => "Ecuador",
"ee" => "Estonia",
"eg" => "Egypt",
"er" => "Eritrea",
"es" => "Spain",
"et" => "Ethiopia",
"fi" => "Finland",
"fj" => "Fiji",
"fk" => "Falkland Islands",
"fo" => "Faroe Islands",
"fr" => "France",
"ga" => "Gabon",
"gb" => "United Kingdom",
"gd" => "Grenada",
"ge" => "Georgia",
"gf" => "French Guiana",
"gg" => "Guernsey",
"gh" => "Ghana",
"gi" => "Gibraltar",
"gl" => "Greenland",
"gm" => "The Gambia",
"gn" => "Guinea",
"gp" => "Guadeloupe",
"gq" => "Equatorial Guinea",
"gr" => "Greece",
"gt" => "Guatemala",
"gu" => "Guam",
"gw" => "Guinea-Bissau",
"gy" => "Guyana",
"hk" => "Hong Kon",
"hn" => "Honduras",
"hr" => "Croatia",
"ht" => "Haiti",
"hu" => "Hungary",
"id" => "Indonesia",
"ie" => "Irelan",
"il" => "Israel",
"im" => "Isle of Man",
"in" => "Indi",
"iq" => "Iraq",
"ir" => "Iran",
"is" => "Iceland",
"it" => "Italy",
"je" => "Jersey",
"jm" => "Jamaica",
"jo" => "Jordan",
"jp" => "Japan",
"ke" => "Kenya",
"kg" => "Kyrgyzstan",
"kh" => "Cambodia",
"ki" => "Kiribati",
"km" => "Comoros",
"kr" => "South Korea",
"kw" => "Kuwait",
"ky" => "Cayman Islands",
"kz" => "Kazakhstan",
"la" => "Laos",
"lb" => "Lebanon",
"lc" => "Saint Lucia",
"li" => "Liechtenstein",
"lk" => "Sri Lanka",
"lr" => "Liberia",
"ls" => "Lesotho",
"lt" => "Lithuania",
"lu" => "Luxembourg",
"lv" => "Latvia",
"ly" => "Libya",
"ma" => "Morocco",
"mc" => "Monaco",
"md" => "Moldova",
"mg" => "Madagascar",
"mh" => "Marshall Islands",
"mk" => "Republic of Macedonia",
"ml" => "Mali",
"mm" => "Myanmar",
"mn" => "Mongolia",
"mp" => "Northern Mariana Islands",
"mq" => "Martinique",
"mr" => "Mauritania",
"ms" => "Montserrat",
"mt" => "Malta",
"mu" => "Mauritius",
"mv" => "Maldives",
"mw" => "Malawi",
"mx" => "Mexico",
"my" => "Malaysia",
"mz" => "Mozambique",
"na" => "Namibia",
"nc" => "New Caledonia",
"ne" => "Niger",
"nf" => "Norfolk Island",
"ng" => "Nigeria",
"ni" => "Nicaragua",
"nl" => "Netherlands",
"no" => "Norway",
"np" => "Nepal",
"nr" => "Nauru",
"nz" => "New Zealand",
"om" => "Oman",
"pa" => "Panama",
"pe" => "Peru",
"pf" => "French Polynesia",
"pg" => "Papua New Guinea",
"ph" => "Philippines",
"pk" => "Pakistan",
"pl" => "Poland",
"pn" => "Pitcairn Islands",
"pr" => "Puerto Rico",
"pt" => "Portugal",
"pw" => "Palau",
"py" => "Paraguay",
"qa" => "Qatar",
"re" => "RÃunion",
"ro" => "Romania",
"ru" => "Russia",
"rw" => "Rwanda",
"sa" => "Saudi Arabia",
"sb" => "Solomon Islands",
"sc" => "Seychelles",
"sd" => "Sudan",
"se" => "Sweden",
"sg" => "Singapore",
"sh" => "Saint Helena",
"si" => "Slovenia",
"sk" => "Slovakia",
"sl" => "Sierra Leone",
"sm" => "San Marino",
"sn" => "Senegal",
"so" => "Somalia",
"sr" => "Suriname",
"st" => "São Tomàand Príncipe",
"su" => "former Soviet Union",
"sv" => "El Salvador",
"sy" => "Syria",
"sz" => "Swazilan",
"td" => "Chad",
"tg" => "Togo",
"th" => "Thailand",
"tj" => "Tajikistan",
"tl" => "East Timor",
"tm" => "Turkmenistan",
"tn" => "Tunisia",
"to" => "Tonga",
"tp" => "East Timor",
"tr" => "Turkey",
"tt" => "Trinidad and Tobago",
"tw" => "Taiwan",
"tz" => "Tanzania",
"ua" => "Ukraine",
"ug" => "Uganda",
"uk" => "United Kingdom",
"um" => "United States Minor Outlying Island",
"uy" => "Uruguay",
"uz" => "Uzbekistan",
"va" => "Vatican City State",
"vc" => "Saint Vincent and the Grenadines",
"ve" => "Venezuela",
"vg" => "British Virgin Islands",
"vi" => "U.S. Virgin Islands",
"vn" => "Vietnam",
"vu" => "Vanuatu",
"wf" => "Wallis and Futuna",
"ws" => "Samoa",
"ye" => "Yemen",
"yt" => "Mayotte",
"yu" => "Yugoslavia",
"za" => "South Africa",
"zm" => "Zambia",
"zw" => "Zimbabwe"
);
$mysession curl_init();
curl_setopt($mysessionCURLOPT_URL"http://.$server/admin.cgi?mode=viewxml");
curl_setopt($mysessionCURLOPT_HEADERfalse);
curl_setopt($mysessionCURLOPT_RETURNTRANSFERtrue);
curl_setopt($mysessionCURLOPT_POSTfalse);
curl_setopt($mysessionCURLOPT_HTTPAUTHCURLAUTH_BASIC);
curl_setopt($mysessionCURLOPT_USERPWD"admin:$password");
curl_setopt($mysessionCURLOPT_FOLLOWLOCATIONtrue);
curl_setopt($mysessionCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT']);
$xml curl_exec($mysession);
curl_close($mysession);
$xml str_replace("&#x27;""'"$xml);
$result "";
$listeners "0";
$maxlisteners "0";
$songs "";
$xml_parser xml_parser_create();
xml_set_element_handler($xml_parser"startElement""endElement");
xml_set_character_data_handler($xml_parser"characterData");
xml_parse($xml_parser$xml);
xml_parser_free($xml_parser);
$do $listeners;
$temp "";
foreach (
$country as $key => $val)
 {
   
$country $countries[$key];
   if (
strlen($country) > 0) {
      
$temp .= ", .$country";
      if (
$val 1)
     
$temp .= " ($val)";
      
$usa -= $val;
   }
}
$result "There are currently $listeners out of $maxlisteners listeners from:\n";
$result .= "DO ($do)$temp";
$result .= $songs;
echo 
trim($result);
function 
startElement($parser$name$attrs) {
   global 
$curTag;
   
$curTag .= "^$name";
}
function 
endElement($parser$name) {
   global 
$curTag;
   
$caret_pos strrpos($curTag'^');
   
$curTag substr($curTag0$caret_pos);
}
function 
characterData($parser$data) {
   global 
$curTag;
   global 
$country;
   global 
$listeners;
   global 
$maxlisteners;
   global 
$songs;
   if (
$curTag == "^SHOUTCASTSERVER^LISTENERS^LISTENER^HOSTNAME") {
      
$parts explode("."$data);
      
$i end($parts);
      
$country[$i]++;
   }
   if (
$curTag == "^SHOUTCASTSERVER^CURRENTLISTENERS") {
      
$listeners $data;
   }
   if (
$curTag == "^SHOUTCASTSERVER^MAXLISTENERS") {
      
$maxlisteners $data;
   }
   if (
$curTag == "^SHOUTCASTSERVER^SONGHISTORY^SONG^TITLE") {
      if (
strpos($data" 0:") === false)
         
$songs .= "\n$data";
   }
}
?>

Es Donde Dice ForEach no tengo Ni Idea de Ese Error, en Mi Servidor Local en Apache Funcionaba Correctamente pero el error comenzó al subirlo al hosting!

Si Alguien Me Prodria Ayudar se lo Agradeceria Muchisimo!!!
#2
Ya que esta consulta no guarda relación con el alojamiento web, lo muevo a
Skylium / Webmaster / Programación Web

El constructor "foreach" no tiene gran misterio. Te aconsejo que le eches un vistazo a http://php.net/manual/es/control-structures.foreach.php donde hay varios ejemplos muy entendibles.
[Imagen: firmabp.jpg][Imagen: mineenlineaentregadispo.jpg]
WWW
#3
Bueno déjame Chekiar porque en Realidad Mi Nivel de Php no es muy Bueno y Ese Ejemplo lo conseguí en la web y lo estaba usando mientras configuraba localmente y me funcionaba muy bn!!! pero al subirlo comenzó a darme ese error y en realidad no se que hacer!!!


Posibles temas similares...
Tema Autor Respuestas Vistas Último mensaje
  [Duda] Necesito traspasar una funcion js a php midd_98 4 196 31-03-2017, 06:05 PM
Último mensaje: avdarie
  Creando la función unzip en php luis.ml 0 202 16-08-2015, 12:57 AM
Último mensaje: luis.ml
  Problemas Sakumo 3 336 17-04-2015, 11:49 PM
Último mensaje: TheBomberbe
  Enviar correos con cabaceras usando la funcion mail() torgar22 0 196 28-02-2015, 02:44 PM
Último mensaje: torgar22
  Problemas con php e irc alemagno 1 291 27-05-2014, 12:50 AM
Último mensaje: softer2
  Problemas con el Estilo de la web. nicoovg 2 512 21-05-2014, 07:26 AM
Último mensaje: nicoovg
  Funcion rand y mt_rand yarq 2 440 07-03-2014, 06:54 PM
Último mensaje: KeviNxDTM
  [ayuda] enviar link en funcion mail() php esteban 3 2,805 15-02-2013, 04:03 AM
Último mensaje: ouch01
  Funcion para calcuar [PHP] classes 3 854 15-06-2012, 04:46 AM
Último mensaje: AbaddonOrmuz
  Pregunta sobre la función "preg_match" mauro770 8 1,618 10-12-2011, 05:20 PM
Último mensaje: Kevin9908



Usuarios navegando en este tema: 1 invitado(s)