1. ¡OFERTA! con cupón "DIRVPS": hosting por $0,01 y también VPS Linux y Windows por $0,01 el primer mes por Interserver ← publi
    Descartar aviso
Descartar aviso
Al usar este sitio web, aceptas que nosotros y nuestros socios podamos establecer cookies para fines tales como personalizar el contenido y la publicidad. Más información.

aprender php

Tema en 'Programación y Diseño Web' iniciado por salvadoresc, 13 Jul 2006.

  1. salvadoresc

    salvadoresc Nuevo usuario

    hola como estan... espero bien

    mi consulta es quien tiene archivos o ejemplos de php que pueda usar para practicarlo ademas que recomendaciones me dan para esto la cuestion es que queremos aprender de php y quisiera tener varios ejemplos en los que pueda trabajar con los compañeros, ya que no tengo total experiencia en esto gracias d antemano :p

    lo que queremos es ejemplos para trabajar y poder ir viendo como funciona... ya tengo un libro se llama "PHP/MySQL Programming for the Absolute Beginner" pero no tengo el cd que este trae... sialguien tuviera el cd tambien me ayudaria muxo
     
  2.  
  3. salvadoresc

    salvadoresc Nuevo usuario

    ademas les traigo ahora una preguntita tengo este codigo... es un ejercicio de una variable

    <!--c1--><div class='codetop'>CÓDIGO</div><div class='codemain'><!--ec1--><html>
    <head>
    <title>Row Your Boat</title>
    </head>
    <body>
    <h1>Row Your Boat</h1>
    <h3>Demonstrates use of long variables</h3>
    <?
    $verse = <<<HERE
    Row, Row, Row, your boat<br>
    Gently down the stream<br>
    Merrily, merrily, merrily, merrily<br>
    Life is but a dream!<br>
    <br><br>
    HERE;
    print "<h3>Verse 1:</h3>";
    print $verse;
    print "<h3>Verse 2:</h3>";
    print $verse;
    print "<h3>Verse 3:</h3>";
    print $verse;
    ?>
    </body>
    </html><!--c2--></div><!--ec2-->

    pero que se hace ese <<<HERE... para que es?


    *******************************************************

    bueno iba a postear esto pero justo encontre la respueste jejejeje asi que en vez de preguntar se los comparto para los que esten aprendiendo...

    esta linea "$verse = <<<HERE" inicializa una variable llamada verse y le asigna una cadena de texto pero esta cadena es de multiples lineas y para conseguir esto utiliza el HERE al principio y al final...

    :p
     
  4. elQuique

    elQuique Usuario activo

    Confieso que vi tu post de comienzo pero hoy tuve un dia a las corridas :) suerte pudiste solucionar ;)
     
  5. salvadoresc

    salvadoresc Nuevo usuario

    si el segundo post lo termine de ver en el libro pero me gustaria siempre tener algunos ejemplos, cosas no muy complicadas, para practicar un poco
     
  6. salvadoresc

    salvadoresc Nuevo usuario

    quiero hacer una consulta adicional.... estoy usando easyphp y quiero activar la opcion

    register_globals = on

    la tengo activada como off en donde lo cambio....
     
  7. elQuique

    elQuique Usuario activo

    lo cambias en el php.ini en tu diretorio de php o en la carpeta windows :)
     
  8. salvadoresc

    salvadoresc Nuevo usuario

    hey quique gracias ya lo hice aunque te comento que cambiarlo de la carpeta php no basto siempre lo tenia activado como off pero luego lo cambie de la carpeta apache y de la carptea conf_files

    son las tres locaciones en las que easyphp guarda los archivos de configuracion de php y al cambiar los tres y reiniciar los servidores entonces me quedo como on....
     
  9. elQuique

    elQuique Usuario activo

    Debe usar solo uno :) pero te comente esos dos ya que era donde podia estar.

    Yo no uso apache, hago rular el PHP sobre el IIS del Windows XP, asi me ahorro tener algo mas que no necesito.
     
  10. salvadoresc

    salvadoresc Nuevo usuario

    otra consulta....


    me he encontrado con problemas a la hora de dejar espacios en blanco antes de algunas instrucciones dentro del codigo y he visto que al dejarlas me genera un error el mensaje siempre dice PARSER ERROR... y apunta a la ultima linea del archivo


    hay algo que pueda hacer para que me ignore esos espacios
    o de encontrar donde esta el error jejeje varias veces he tonteado un resto por un espacio en blanco y segun entendi php los ignora (no entiendo que pasa)

    gracias de nuevo
     
  11. elQuique

    elQuique Usuario activo

    mmm bueno que editor usas ??

    depende este el espacio en blanco dara error o no, el tema del parse suele pasar mas por olvidarse de una comilla y mezclar alguna llave, seria bueno ve el codigo y saber el editor
     
  12. salvadoresc

    salvadoresc Nuevo usuario

    pues fijate que para aprenderlo solamente estoy usando el bloc de notas y pues lo unico fue que por ejemplo antes de un print habia 3 espacios en blanco y me daba error y como te mencione el error apunta a la ultima linea del archivo, justo en la viñeta de cierre de html

    bueno mira a ca te dejo el codgio es un juego de poker con dados... es un ejercicio que salia en el libro

    <!--c1--><div class='codetop'>CÓDIGO</div><div class='codemain'><!--ec1-->
    <html>
    <head>
    <title>poker dice</title>
    <style type = "text/css">
    body {
    background: green;
    color: tan;
    }
    </style>
    </head>
    <body>
    <center>
    <h1>Poker Dice</h1>
    <form>

    <?
    //check to see if this is first time here
    if (empty($cash)){
    $cash = 100;
    } // end if
    rollDice();
    if ($secondRoll == TRUE){
    print "<h2>Second roll</h2>\n";
    $secondRoll = FALSE;
    evaluate();
    } else {
    print "<h2>First roll</h2>\n";
    $secondRoll = TRUE;
    } // end if
    printStuff();
    function rollDice(){
    global $die, $secondRoll, $keepIt;
    print "<table border = 1><td><tr>";
    for ($i = 0; $i < 5; $i++){
    if ($keepIt[$i] == ""){
    $die[$i] = rand(1, 6);
    } else {
    $die[$i] = $keepIt[$i];
    } // end if
    $theFile = "die" . $die[$i] . ".jpg";
    //print out dice images
    print <<<HERE
    <td>
    <img src = "$theFile"
    height = 50
    width = 50><br>
    HERE;
    //print out a checkbox on first roll only
    if ($secondRoll == FALSE){
    print <<<HERE
    <input type = "checkbox"
    name = "keepIt[$i]"
    value = $die[$i]>
    </td>
    HERE;
    } // end if
    } // end for loop
    //print out submit button and end of table
    print <<<HERE
    </tr></td>
    <tr>
    <td colspan = "5">
    <center>
    <input type = "submit"
    value = "roll again">
    </center>
    </td>
    </tr>
    </table>
    HERE;
    } // end rollDice
    if ($keepIt[$i] == ""){
    $die[$i] = rand(1, 6);
    } else {
    $die[$i] = $keepIt[$i];
    } // end if
    $theFile = "die" . $die[$i] . ".jpg";
    //print out dice images
    print <<<HERE
    <td>
    <img src = "$theFile"
    height = 50
    width = 50><br>
    HERE;
    //print out a checkbox on first roll only
    if ($secondRoll == FALSE){
    print <<<HERE
    <input type = "checkbox"
    name = "keepIt[$i]"
    value = $die[$i]>
    </td>
    HERE;
    } // end if
    //print out submit button and end of table
    print <<<HERE
    </tr></td>
    <tr>
    <td colspan = "5">
    <center>
    <input type = "submit"
    value = "roll again">
    </center>
    </td>
    </tr>
    </table>
    HERE;
    function evaluate(){
    global $die, $cash;
    //set up payoff
    $payoff = 0;
    //subtract some money for this roll
    $cash -= 2;
    //count the dice
    $numVals = array(6);
    for ($theVal = 1; $theVal <= 6; $theVal++){
    for ($dieNum = 0; $dieNum < 5; $dieNum++){
    if ($die[$dieNum] == $theVal){
    $numVals[$theVal]++;
    } // end if
    } // end dieNum for loop
    } // end theVal for loop
    //print out results
    // for ($i = 1; $i <= 6; $i++){
    // print "$i: $numVals[$i]<br>\n";
    // } // end for loop
    //count how many pairs, threes, fours, fives
    $numPairs = 0;
    $numThrees = 0;
    $numFours = 0;
    $numFives = 0;
    for ($i = 1; $i <= 6; $i++){
    switch ($numVals[$i]){
    case 2:
    $numPairs++;
    break;
    case 3:
    $numThrees++;
    break;
    case 4:
    $numFours++;
    break;
    case 5:
    $numFives++;
    break;
    } // end switch
    } // end for loop
    //check for two pairs
    if ($numPairs == 2){
    print "You have two pairs!<br>\n";
    $payoff = 1;
    } // end if
    //check for three of a kind and full house
    if ($numThrees == 1){
    if ($numPairs == 1){
    //three of a kind and a pair is a full house
    print "You have a full house!<br>\n";
    $payoff = 5;
    } else {
    print "You have three of a kind!<br>\n";
    $payoff = 2;
    } // end 'pair' if
    } // end 'three' if
    //check for four of a kind
    if ($numFours == 1){
    print "You have four of a kind!<br>\n";
    $payoff = 5;
    } // end if
    //check for five of a kind
    if ($numFives == 1){
    print "You got five of a kind!<br>\n";
    $payoff = 10;
    } // end if
    //check for flushes
    if (($numVals[1] == 1)
    && ($numVals[2] == 1)
    && ($numVals[3] == 1)
    && ($numVals[4] == 1)
    && ($numVals[5] == 1)){
    print "You have a flush!<br>\n";
    $payoff = 10;
    } // end if
    if (($numVals[2] == 1)
    && ($numVals[3] == 1)
    && ($numVals[4] == 1)
    && ($numVals[5] == 1)
    && ($numVals[6] == 1)){
    print "You have a flush!<br>\n";
    $payoff = 10;
    } // end if
    print "You bet 2<br>\n";
    print "Payoff is $payoff<br>\n";
    $cash += $payoff;
    } // end evaluate
    //count the dice
    for ($theVal = 1; $theVal <= 6; $theVal++){
    for ($dieNum = 0; $dieNum < 5; $dieNum++){
    if ($die[$dieNum] == $theVal){
    $numVals[$theVal]++;
    } // end if
    } // end dieNum for loop
    } // end theVal for loop
    //print out results
    // for ($i = 1; $i <= 6; $i++){
    // print "$i: $numVals[$i]<br>\n";
    // } // end for loop
    //count how many pairs, threes, fours, fives
    $numPairs = 0;
    $numThrees = 0;
    $numFours = 0;
    $numFives = 0;
    for ($i = 1; $i <= 6; $i++){
    switch ($numVals[$i]){
    case 2:
    $numPairs++;
    break;
    case 3:
    $numThrees++;
    break;
    case 4:
    $numFours++;
    break;
    case 5:
    $numFives++;
    break;
    } // end switch
    } // end for loop
    //check for two pairs
    if ($numPairs == 2){
    print "You have two pairs!<br>\n";
    $payoff = 1;
    } // end if
    //check for three of a kind and full house
    if ($numThrees == 1){
    if ($numPairs == 1){
    //three of a kind and a pair is a full house
    print "You have a full house!<br>\n";
    $payoff = 5;
    } else {
    print "You have three of a kind!<br>\n";
    $payoff = 2;
    } // end 'pair' if
    } // end 'three' if
    //check for four of a kind
    if ($numFours == 1){
    print "You have four of a kind!<br>\n";
    $payoff = 5;
    } // end if
    //check for five of a kind
    if ($numFives == 1){
    print "You got five of a kind!<br>\n";
    $payoff = 10;
    } // end if
    //check for straights
    if (($numVals[1] == 1)
    && ($numVals[2] == 1)
    && ($numVals[3] == 1)
    && ($numVals[4] == 1)
    && ($numVals[5] == 1)){
    print "You have a straight!<br>\n";
    $payoff = 10;
    } // end if
    if (($numVals[2] == 1)
    && ($numVals[3] == 1)
    && ($numVals[4] == 1)
    && ($numVals[5] == 1)
    && ($numVals[6] == 1)){
    print "You have a straight!<br>\n";
    $payoff = 10;
    function printStuff(){
    global $cash, $secondRoll;
    print "Cash: $cash\n";
    //store variables in hidden fields
    print <<<HERE
    <input type = "hidden"
    name = "secondRoll"
    value = "$secondRoll">
    <input type = "hidden"
    name = "cash"
    value = "$cash">
    HERE;
    } // end printStuff
    ?>
    </center>
    </body>
    </html>
    <!--c2--></div><!--ec2-->

    lo estoy revisando pero no me corre... a los otros si les quite los espacios que habia insertado con la barra y funcionaron... extraño
     
  13. salvadoresc

    salvadoresc Nuevo usuario

    hey traigo otra duda a ver si alguien me encuentra un error en esto es que por mas que le busco no se lo encuentro me die que tengo error en la linea 39, 90, 104, y 134



    aca les dejo el codigo.. es un juego de poker con dados que aparece en el libro

    <!--c1--><div class='codetop'>CÓDIGO</div><div class='codemain'><!--ec1--> <html>
    <head>
    <title>poker dice</title>
    <style type = "text/css">
    body {
    background: green;
    color: tan;
    }
    </style>
    </head>
    <body>
    <center>
    <h1>Poker Dice</h1>
    <form>
    <?


    //check to see if this is first time here
    if (empty($cash)){
    $cash = 100;
    } // end if
    rollDice();
    if ($secondRoll == TRUE){
    print "<h2>Second roll</h2>\n";
    $secondRoll = FALSE;
    evaluate();
    } else {
    print "<h2>First roll</h2>\n";
    $secondRoll = TRUE;
    } // end if
    printStuff();



    function rollDice(){
    global $die, $secondRoll, $keepIt;
    print "<table border = 1><td><tr>";
    for ($i = 0; $i < 5; $i++){
    if ($keepIt[$i] == ""){
    $die[$i] = rand(1, 6);
    } else {
    $die[$i] = $keepIt[$i];
    } // end if
    $theFile = "die" . $die[$i] . ".jpg";
    //print out dice images
    print <<<HERE
    <td>
    <img src = "$theFile"
    height = 50
    width = 50><br>
    HERE;
    //print out a checkbox on first roll only
    if ($secondRoll == FALSE){
    print <<<HERE
    <input type = "checkbox"
    name = "keepIt[$i]"
    value = $die[$i]>
    </td>
    HERE;
    } // end if
    } // end for loop
    //print out submit button and end of table
    print <<<HERE
    </tr></td>
    <tr>
    <td colspan = "5">
    <center>
    <input type = "submit"
    value = "roll again">
    </center>
    </td>
    </tr>
    </table>
    HERE;
    } // end rollDice



    function evaluate(){
    global $die, $cash;
    //set up payoff
    $payoff = 0;
    //subtract some money for this roll
    $cash -= 2;
    //count the dice
    $numVals = array(6);
    for ($theVal = 1; $theVal <= 6; $theVal++){
    for ($dieNum = 0; $dieNum < 5; $dieNum++){
    if ($die[$dieNum] == $theVal){
    $numVals[$theVal]++;
    } // end if
    } // end dieNum for loop
    } // end theVal for loop
    //print out results
    // for ($i = 1; $i <= 6; $i++){
    // print "$i: $numVals[$i]<br>\n";
    // } // end for loop
    //count how many pairs, threes, fours, fives
    $numPairs = 0;
    $numThrees = 0;
    $numFours = 0;
    $numFives = 0;
    for ($i = 1; $i <= 6; $i++){
    switch ($numVals[$i]){
    case 2:
    $numPairs++;
    break;
    case 3:
    $numThrees++;
    break;
    case 4:
    $numFours++;
    break;
    case 5:
    $numFives++;
    break;
    } // end switch
    } // end for loop
    //check for two pairs
    if ($numPairs == 2){
    print "You have two pairs!<br>\n";
    $payoff = 1;
    } // end if
    //check for three of a kind and full house
    if ($numThrees == 1){
    if ($numPairs == 1){
    //three of a kind and a pair is a full house
    print "You have a full house!<br>\n";
    $payoff = 5;
    } else {
    print "You have three of a kind!<br>\n";
    $payoff = 2;
    } // end 'pair' if
    } // end 'three' if
    //check for four of a kind
    if ($numFours == 1){
    print "You have four of a kind!<br>\n";
    $payoff = 5;
    } // end if
    //check for five of a kind
    if ($numFives == 1){
    print "You got five of a kind!<br>\n";
    $payoff = 10;
    } // end if
    //check for flushes
    if (($numVals[1] == 1)
    && ($numVals[2] == 1)
    && ($numVals[3] == 1)
    && ($numVals[4] == 1)
    && ($numVals[5] == 1)){
    print "You have a flush!<br>\n";
    $payoff = 10;
    } // end if
    if (($numVals[2] == 1)
    && ($numVals[3] == 1)
    && ($numVals[4] == 1)
    && ($numVals[5] == 1)
    && ($numVals[6] == 1)){
    print "You have a flush!<br>\n";
    $payoff = 10;
    } // end if
    print "You bet 2<br>\n";
    print "Payoff is $payoff<br>\n";
    $cash += $payoff;
    } // end evaluate



    function printStuff(){
    global $cash, $secondRoll;
    print "Cash: $cash\n";
    //store variables in hidden fields
    print <<<HERE
    <input type = "hidden"
    name = "secondRoll"
    value = "$secondRoll">
    <input type = "hidden"
    name = "cash"
    value = "$cash">
    HERE;
    } // end printStuff

    ?>
    </form>
    </center>
    </body>
    </html><!--c2--></div><!--ec2-->
     
  14. elQuique

    elQuique Usuario activo

    A mi personalmente no me gustan los <<<HERE y los HERE, lo que hice fue buscar y sustituir los <<<HERE por una comilla simple ' y el HERE tambien y listo

    <a href="http://www.forocreativo.net/test.php" target="_blank">http://www.forocreativo.net/test.php</a>

    No se si usas DW pero el usar el html dentro de una cadena realmente queda engorroso de entender, ya que si lo usas de otro forma los colores te ayudaran a entender mejor estas cosillas que nos retrasan pero que son por una simple Comilla '
     
  15. salvadoresc

    salvadoresc Nuevo usuario

    o sea que ambos se cambian por la comilla?

    otra pregunta yo veo que en los ejercicios de este lbro utilizan solo "print"

    pero yo he visto en algunos scripts utilizando "echo" existe alguna diferencia o ventaja en estos?

    y muxas gracias quique
    :pompones:
     


Alojamiento web, Hosting Reseller, Servidores Dedicados - All in Hosting


    
    
    
    
Blog · Sitios amigos: GuiaHosting · Unidominios · Interalta ·