Foros del Web » Programando para Internet » PHP »

php xml

Estas en el tema de php xml en el foro de PHP en Foros del Web. por favor ayudenme a crear un xml playlist para mi reproductor usando PHP <?xml version="1.0" encoding="UTF-8"?> <songs> <song title="aki titulo de cancion" path="aki ruta"/> </songs> ...
  #1 (permalink)  
Antiguo 02/02/2011, 19:12
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
php xml

por favor ayudenme a crear un xml playlist para mi reproductor usando PHP

<?xml version="1.0" encoding="UTF-8"?>
<songs>
<song title="aki titulo de cancion" path="aki ruta"/>
</songs>

tengo un html que sube archivos con nombres y la ruta (la ruta y el nombre los guarda en la base de datos) consulatando la base de datos me da los registros

bueno pero haber si me pueden dar el codigo explicado para hacer mi xml playlist
  #2 (permalink)  
Antiguo 02/02/2011, 20:15
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: php xml

¿En donde es que tienes la duda exactamente? ¿Que tanto sabes de PHP?
  #3 (permalink)  
Antiguo 03/02/2011, 08:23
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
Respuesta: php xml

bueno te explico ...
estoy creando un xml con el php sin enbargo me este error...
Parse error: syntax error, unexpected T_VARIABLE, expecting ',' or ';' in /home/derzz/public_html/play.php on line 32
no se que pasa pero es diferente a la estructura de arriba.
me gustaria que me ayudaran a crear la estructura de arriba con php
  #4 (permalink)  
Antiguo 03/02/2011, 08:44
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: php xml

Muestra el codigo que tienes ...
  #5 (permalink)  
Antiguo 03/02/2011, 08:46
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
Código PHP:
Ver original
  1. <?php
  2.  
  3. /*
  4. This is a sample file that extracts a list of records from a mysql database and
  5. builds a playlist from it. After looking through this file, you'll probably
  6. 'get the idea' and'll be able to connect the flash player
  7. to your own database.
  8. */
  9.  
  10.  
  11. // first connect to database
  12. $dbcnx = @mysql_connect("localhost","derzz_web","c4rl0z!");
  13. $dbselect = @mysql_select_db("derzz_musik");
  14. if ((!$dbcnx) || (!$dbselect)) { echo "Can't connect to database"; }
  15.  
  16.  
  17. // next, query for a list of titles, files and links.
  18. $query = "SELECT nombre,ruta FROM archivos_mp3";
  19. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  20.  
  21.  
  22. // third, the playlist is built in an xspf format
  23. // we'll first add an xml header and the opening tags ..
  24. header("content-type:text/xml;charset=utf-8");
  25.  
  26.  
  27. echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
  28. echo "<songs>\n";
  29.  
  30. // .. then we loop through the mysql array ..
  31. while($row = @mysql_fetch_array($result)) {
  32.     echo "<song title=".$row['nombre']."path=".$row['ruta']."/>\n";
  33.    
  34. }
  35. //<song title="La amante - grupo 5" path="llamado.mp3"/>
  36. // .. and last we add the closing tags
  37. echo "</songs>\n";
  38.  
  39.  
  40.  
  41. /*
  42. That's it! You can feed this playlist to the SWF by setting this as it's 'file'
  43. parameter in your HTML.
  44. */
  45.  
  46. ?>

me dice k hay un problema en la linea 32

Última edición por GatorV; 03/02/2011 a las 09:34
  #6 (permalink)  
Antiguo 03/02/2011, 09:37
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
Respuesta: php xml

lo volvi a configurar y me vota esto
Código HTML:
Ver original
  1. No se puede mostrar la página XML
  2. No se puede ver la entrada XML con la hoja de estilo XSL. Corrija el error y haga clic en el botón Actualizar o inténtelo de nuevo más tarde.
  3.  
  4.  
  5. --------------------------------------------------------------------------------
  6.  
  7. Se esperaba una cadena literal, pero no se encontraron las comillas de apertura. Error al procesar el recurso http://derzz....
  8.  
  9. <song title=songderzzpath=upload/song.mp3/>
  10. ------------^
  #7 (permalink)  
Antiguo 03/02/2011, 09:48
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: php xml

No estas imprimiendo las comillas para los atributos en la etiqueta <song>
  #8 (permalink)  
Antiguo 03/02/2011, 10:19
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
Respuesta: php xml

si si lo he puesto
Código PHP:
Ver original
  1. echo "<songs>\n"; // .. then we loop through the mysql array ..while($row = @mysql_fetch_array($result)) {    echo "<song title=".$row['nombre']."path=".$row['ruta']."/>\n";    }//<song title="La amante - grupo 5" path="llamado.mp3"/>// .. and last we add the closing tagsecho "</songs>\n";
  #9 (permalink)  
Antiguo 03/02/2011, 10:44
Avatar de Ronruby  
Fecha de Ingreso: julio-2008
Ubicación: 18°30'N, 69°59'W
Mensajes: 4.879
Antigüedad: 15 años, 9 meses
Puntos: 416
Respuesta: php xml

Me refiero a esta linea:
Código PHP:
Ver original
  1. echo "<song title=".$row['nombre']."path=".$row['ruta']."/>\n";
  #10 (permalink)  
Antiguo 03/02/2011, 11:56
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
pero esta igual
om como deberia ser
Código PHP:
Ver original
  1. "<song title=".$row['nombre']."path=".$row['ruta']."/>\n";

ayudenme con este codigo
Código PHP:
Ver original
  1. <?php
  2.  
  3. /*
  4. This is a sample file that extracts a list of records from a mysql database and
  5. builds a playlist from it. After looking through this file, you'll probably
  6. 'get the idea' and'll be able to connect the flash player
  7. to your own database.
  8. */
  9.  
  10.  
  11. // first connect to database
  12. $dbcnx = @mysql_connect("localhost","derzz_web","xxxxxx");
  13. $dbselect = @mysql_select_db("derzz_musik");
  14. if ((!$dbcnx) || (!$dbselect)) { echo "Can't connect to database"; }
  15.  
  16.  
  17. // next, query for a list of titles, files and links.
  18. $query = "SELECT nombre,ruta FROM archivos_mp3";
  19. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  20.  
  21.  
  22. // third, the playlist is built in an xspf format
  23. // we'll first add an xml header and the opening tags ..
  24. header("content-type:text/xml;charset=utf-8");
  25.  
  26.  
  27. echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
  28. echo "  <songs>\n";
  29.  
  30. // .. then we loop through the mysql array ..
  31. while($row = @mysql_fetch_array($result)) {
  32.     echo "<song title="$row['nombre']" path="$row['ruta']"/>\n";
  33.    
  34. }
  35.  
  36. // .. and last we add the closing tags
  37. echo "  </songs>\n";
  38.  
  39.  
  40.  
  41. /*
  42. That's it! You can feed this playlist to the SWF by setting this as it's 'file'
  43. parameter in your HTML.
  44. */
  45.  
  46. ?>
quiero hacer la estructura de un XML UTF-8 pero me da error no se como hacerlo
nota: los dato los obtiene de la base de datos que los pone en un bucle
Código PHP:
Ver original
  1. echo "<song title="$row['nombre']" path="$row['ruta']"/>\n";
tengo que canmbiar esta parte
Código PHP:
Ver original
  1. <playlist version='1' xmlns='http://xspf.org/ns/0/'>
por esta
Código PHP:
Ver original
  1. <?xml version="1.0" encoding="UTF-8"?>

de la linea 27

Última edición por GatorV; 04/02/2011 a las 15:14
  #11 (permalink)  
Antiguo 04/02/2011, 14:50
Avatar de atoBeto  
Fecha de Ingreso: abril-2008
Ubicación: B.C.S., México
Mensajes: 35
Antigüedad: 16 años
Puntos: 2
Respuesta: ayuda php porfavor

Al primer código que estás poniendo le falta cerrar el cuerpo de la primer etiqueta XML:

Código XML:
Ver original
  1. </playlist>

Por otro lado, no veo que tengas que cambiar es línea de la 27, simplemente tendrías que añadir esa etiqueta antes que <playlist>. Osea:

Código XML:
Ver original
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <playlist version='1' xmlns='http://xspf.org/ns/0/'>
  3.    ...
  4.  </playlist>
  #12 (permalink)  
Antiguo 04/02/2011, 14:52
Avatar de bUllan9ebrio  
Fecha de Ingreso: enero-2011
Ubicación: Chile
Mensajes: 1.128
Antigüedad: 13 años, 2 meses
Puntos: 128
Respuesta: ayuda php porfavor

Código PHP:
Ver original
  1. 1.
  2.       <?xml version="1.0" encoding="UTF-8"?>


esta mal, por que mejor no sacas los tags o mandas un echo :

Código PHP:
Ver original
  1. 1.
  2.       <?php echo "xml version='1.0' encoding='UTF-8'; ?>
  #13 (permalink)  
Antiguo 04/02/2011, 14:53
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
no.... esa es la parte q quiero cambiar
por la otra

si ya probe asi pero no... me sale error

disculpenme por no explicaarme..
es para un reproductor flash que va a abrir el xml en php
obteniendo los datos del DB

y trabaja en UTF-8

lo he cambiado la linea 27 asi
Código PHP:
Ver original
  1. <?php
  2.  
  3. /*
  4. This is a sample file that extracts a list of records from a mysql database and
  5. builds a playlist from it. After looking through this file, you'll probably
  6. 'get the idea' and'll be able to connect the flash player
  7. to your own database.
  8. */
  9.  
  10.  
  11. // first connect to database
  12. $dbcnx = @mysql_connect("localhost","derzz_web","c4rl0z!");
  13. $dbselect = @mysql_select_db("derzz_musik");
  14. if ((!$dbcnx) || (!$dbselect)) { echo "Can't connect to database"; }
  15.  
  16.  
  17. // next, query for a list of titles, files and links.
  18. $query = "SELECT nombre,ruta FROM archivos_mp3";
  19. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  20.  
  21.  
  22. // third, the playlist is built in an xspf format
  23. // we'll first add an xml header and the opening tags ..
  24. header("content-type:text/xml;charset=utf-8");
  25.  
  26.  
  27. echo "<?xml version="1.0" encoding="utf-8"?>\n";
  28. echo "  <songs>\n";
  29.  
  30. // .. then we loop through the mysql array ..
  31. while($row = @mysql_fetch_array($result)) {
  32.     echo "<song title="$row['nombre']" path="$row['ruta']"/>\n";
  33.    
  34. }
  35. //<song title="La amante - grupo 5" path="llamado.mp3"/>
  36. // .. and last we add the closing tags
  37. echo "  </songs>\n";
  38.  
  39.  
  40.  
  41. /*
  42. That's it! You can feed this playlist to the SWF by setting this as it's 'file'
  43. parameter in your HTML.
  44. */
  45.  
  46. ?>
pero me da el error
Parse error: syntax error, unexpected T_DNUMBER, expecting ',' or ';' in /home/derzz/domains/derzz.leehoan.com/public_html/play.php on line 27 ayudenme

Última edición por GatorV; 04/02/2011 a las 15:11
  #14 (permalink)  
Antiguo 04/02/2011, 15:12
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: ayuda php porfavor

Lee lo siguiente: http://www.forosdelweb.com/f18/como-...1/#post2414268

Saludos.

PD Por favor NO dupliques temas.

Temas unidos.
  #15 (permalink)  
Antiguo 04/02/2011, 15:19
Avatar de bullarobert  
Fecha de Ingreso: enero-2011
Mensajes: 31
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: php xml

coloca el codigo de esta forma:

Código PHP:
Ver original
  1. <?php
  2.  
  3. /*
  4. This is a sample file that extracts a list of records from a mysql database and
  5. builds a playlist from it. After looking through this file, you'll probably
  6. 'get the idea' and'll be able to connect the flash player
  7. to your own database.
  8. */
  9.  
  10.  
  11. // first connect to database
  12. $dbcnx = @mysql_connect("localhost","derzz_web","c4rl0z!");
  13. $dbselect = @mysql_select_db("derzz_musik");
  14. if ((!$dbcnx) || (!$dbselect)) { echo "Can't connect to database"; }
  15.  
  16.  
  17. // next, query for a list of titles, files and links.
  18. $query = "SELECT nombre,ruta FROM archivos_mp3";
  19. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  20.  
  21.  
  22. // third, the playlist is built in an xspf format
  23. // we'll first add an xml header and the opening tags ..
  24. header("content-type:text/xml;charset=utf-8");
  25.  
  26.  
  27. echo "<?xml version='1.0' encoding='utf-8'?>\n";
  28. echo "  <songs>\n";
  29.  
  30. // .. then we loop through the mysql array ..
  31. while($row = @mysql_fetch_array($result)) {
  32.     echo "<song title='$row['nombre']' path='$row['ruta']'/>\n";
  33.    
  34. }
  35. //<song title="La amante - grupo 5" path="llamado.mp3"/>
  36. // .. and last we add the closing tags
  37. echo "  </songs>\n";
  38.  
  39.  
  40.  
  41. /*
  42. That's it! You can feed this playlist to the SWF by setting this as it's 'file'
  43. parameter in your HTML.
  44. */
  45.  
  46. ?>

en varias partes tenias comillas dobles, dentro de los echo van comillas simple, prueba y me dices como te fue
  #16 (permalink)  
Antiguo 04/02/2011, 15:46
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
Respuesta: php xml

me genera esto

No se puede mostrar la página XML
No se puede ver la entrada XML con la hoja de estilo XSL. Corrija el error y haga clic en el botón Actualizar o inténtelo de nuevo más tarde.


--------------------------------------------------------------------------------

Se esperaba una cadena literal, pero no se encontraron las comillas de apertura. Error al procesar el recurso http://derzz....

<song title=eternos recuerdos - 8 puntos clanpath=8 puntos clan eternos recuerdos.mp3/>
------------^
  #17 (permalink)  
Antiguo 04/02/2011, 15:57
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: php xml

Ya te lo dijeron, los atributos de todas las etiquetas deben estar entre comillas:

<song title="este es el titulo" path="esta es la ruta" />

Y, ademas, si tienes espacios en el nombre de los archivos tal vez tengas que usar la funcion urlencode() para evitar problemas.
__________________
- León, Guanajuato
- GV-Foto
  #18 (permalink)  
Antiguo 04/02/2011, 16:06
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
Respuesta: php xml

ya aki esta en comillas simples
Código PHP:
Ver original
  1. <?php
  2.  
  3. /*
  4. This is a sample file that extracts a list of records from a mysql database and
  5. builds a playlist from it. After looking through this file, you'll probably
  6. 'get the idea' and'll be able to connect the flash player
  7. to your own database.
  8. */
  9.  
  10.  
  11. // first connect to database
  12. $dbcnx = @mysql_connect("localhost","derzz_web","c4rl0z!");
  13. $dbselect = @mysql_select_db("derzz_db");
  14. if ((!$dbcnx) || (!$dbselect)) { echo "Can't connect to database"; }
  15.  
  16.  
  17. // next, query for a list of titles, files and links.
  18. $query = "SELECT nombre,ruta FROM archivos_mp3";
  19. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  20.  
  21.  
  22. // third, the playlist is built in an xspf format
  23. // we'll first add an xml header and the opening tags ..
  24. header("content-type:text/xml;charset=utf-8");
  25.  
  26.  
  27. echo '<?xml version="1.0" encoding="utf-8"?>\n';
  28. echo '  <songs>\n';
  29.  
  30. // .. then we loop through the mysql array ..
  31. while($row = @mysql_fetch_array($result)) {
  32.     echo '<song title="'|||.$row['nombre']'"' 'path="'.$row['ruta'] '"/>\n';
  33.    
  34. }
  35. //<song title="La amante - grupo 5" path="llamado.mp3"/>
  36. // .. and last we add the closing tags
  37. echo '  </songs>\n';
  38.  
  39.  
  40.  
  41. /*
  42. That's it! You can feed this playlist to the SWF by setting this as it's 'file'
  43. parameter in your HTML.
  44. */
  45.  
  46. ?>
  #19 (permalink)  
Antiguo 04/02/2011, 16:09
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
Respuesta: php xml

Código PHP:
Ver original
  1. <?php
  2.  
  3. /*
  4. This is a sample file that extracts a list of records from a mysql database and
  5. builds a playlist from it. After looking through this file, you'll probably
  6. 'get the idea' and'll be able to connect the flash player
  7. to your own database.
  8. */
  9.  
  10.  
  11. // first connect to database
  12. $dbcnx = @mysql_connect("localhost","derzz_web","c4rl0z!");
  13. $dbselect = @mysql_select_db("derzz_db");
  14. if ((!$dbcnx) || (!$dbselect)) { echo "Can't connect to database"; }
  15.  
  16.  
  17. // next, query for a list of titles, files and links.
  18. $query = "SELECT nombre,ruta FROM archivos_mp3";
  19. $result = mysql_query($query) or die('Query failed: ' . mysql_error());
  20.  
  21.  
  22. // third, the playlist is built in an xspf format
  23. // we'll first add an xml header and the opening tags ..
  24. header("content-type:text/xml;charset=utf-8");
  25.  
  26. echo '<?xml version="1.0" encoding="utf-8"?>\n';
  27. echo '  <songs>\n';
  28.  
  29. // .. then we loop through the mysql array ..
  30. while($row = @mysql_fetch_array($result)) {
  31.     echo '<song title="'.$row['nombre']'"' 'path="'.$row['ruta'] '"/>\n';
  32.    
  33. }
  34. //<song title="La amante - grupo 5" path="llamado.mp3"/>
  35. // .. and last we add the closing tags
  36. echo '  </songs>\n';
  37.  
  38.  
  39. /*
  40. That's it! You can feed this playlist to the SWF by setting this as it's 'file'
  41. parameter in your HTML.
  42. */
  43.  
  44. ?>
  #20 (permalink)  
Antiguo 04/02/2011, 16:11
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
Respuesta: php xml

me genero este error
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/derzz/domains/derzz.leehoan.com/public_html/play.php on line 32
  #21 (permalink)  
Antiguo 04/02/2011, 16:14
Avatar de bullarobert  
Fecha de Ingreso: enero-2011
Mensajes: 31
Antigüedad: 13 años, 2 meses
Puntos: 0
Respuesta: php xml

esta linea va asi si no me equivoco:
Código PHP:
Ver original
  1. echo '<song title="'.$row['nombre'].'"' 'path="'.$row['ruta']. '"/>\n';
  #22 (permalink)  
Antiguo 04/02/2011, 16:17
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
si asi la eh colocado

no hay otra forma de crear esta estructura con php
Código XML:
Ver original
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <songs>
  3. <song title="aki titulo de cancion" path="aki ruta"/>
  4. </songs>

Última edición por GatorV; 04/02/2011 a las 16:26
  #23 (permalink)  
Antiguo 04/02/2011, 17:08
Avatar de Triby
Mod on free time
 
Fecha de Ingreso: agosto-2008
Ubicación: $MX->Gto['León'];
Mensajes: 10.106
Antigüedad: 15 años, 8 meses
Puntos: 2237
Respuesta: php xml

Tan facil como abrir y cerrar etiquetas de PHP:

Código PHP:
Ver original
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <songs>
  3. <song title="<?php echo $variable1; ?>" path="<?php echo $variable2; ?>" />
  4. </songs>
__________________
- León, Guanajuato
- GV-Foto
  #24 (permalink)  
Antiguo 04/02/2011, 17:43
 
Fecha de Ingreso: enero-2011
Mensajes: 112
Antigüedad: 13 años, 2 meses
Puntos: 4
y en ke extenzion lo guardo php o xml??

bueno gracias ya lo arregle

Última edición por GatorV; 05/02/2011 a las 18:20

Etiquetas: derzz, xml
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:18.