Jump to content

TransmogriBenno

Members
  • Posts

    61
  • Joined

  • Last visited

    Never

Posts posted by TransmogriBenno

  1. Do you know what part of the code is the problem?

    Have you checked that the result from file() is what you want, and that

    $parts_array[$i] = explode($delimiter,$data_array[$i]);

    is doing what you expect it to?

  2. You just remove the else wrapper:

     

    <?php
    // If the form has been submitted...
    if(isset($_POST['submit']))
    {
    // Set $name as the value of the name field in your form ($_POST just references the form)
    $name = $_POST['name'];
    }
    
    // Display the form
    echo '<form name="form" method="post">
    <input type="text" name="name" size="27" value=$name" />
    <input type="submit" name="submit" value="Go">
    </form>';
    ?>

  3. Please use code tags when inserting code.

     

    Something like the following modifications should do the trick:

     

    <?php
      $doc = new DOMDocument();
      $doc->load( 'books.xml' );
      
      /* MOD */ $book_num = 1;
      /* MOD */ $start = 11;
      /* MOD */ $end = 20;
      
      $books = $doc->getElementsByTagName( "book" );
      foreach( $books as $book )
      {
      $authors = $book->getElementsByTagName( "author" );
      $author = $authors->item(0)->nodeValue;
    
      $publishers = $book->getElementsByTagName( "publisher" );
      $publisher = $publishers->item(0)->nodeValue;
    
      $titles = $book->getElementsByTagName( "title" );
      $title = $titles->item(0)->nodeValue;
      /* MOD */ if ($book_num >= $start) echo "$title - $author - $publisher\n";
      /* MOD */ if (++$book_num > $end) break;
      }
      ?>

  4. Why do you want to do that?

     

    I think a better solution would be to store the short (e.g. NY) and long (e.g. New York) names in, say, a 'States' table the database, and then reference them using a key. You could use the short name as the key.

  5. I'm guessing it has something to do with:

     

    $mail->WordWarp

     

    This is invalid syntax, and (not being familiar with the class), I'm not sure of the point of it. Is is meant to be WordWrap? I'm assuming that's a function. So perhaps:

     

    $mail->WordWrap ();

  6. I would suggest instead of doing a loop through all the days to work out how many sundays have passed, you just get the number of weeks passed by dividing the number of days passed by 7 (round down), and then since you know what day of the week the starting day was, you can work out if another sunday has passed during the remainder of days. Presumably this would be faster, as you essentially only have 2 calculations per row.

     

    There's obviously a significant amount of code missing, and judging by the foreign language (French?) comments, I'm assuming you've changed variable names to make the script readable (I guess $jourSemaine1 should be $dayweek, otherwise the code doesn't make a lot of sense). I get the feeling that you're counting the number of days in each week that has transpired in $nbrdays, though I'm not sure why. You initialise it with 52 values, all zero, so I'm assuming later in the code you're expecting it to have only 52 elements, which is not the case if the total number of weeks you cycle through is > 52.

  7. There is no code that can be executed after he sends the Location header so calling die() is useless in this case.

    What I'm saying is that it's good practice, otherwise you can end up in a situation like this:

    <?php
    if (!$logged_in) {
      header ('Location: login.php');
    }
    ?>
    Hello, logged in user. Here's the secret/private stuff you are accessing.

    In this case, the secret/private stuff is sent to the client along with the location header, which means that anyone using a net debugger or special browser will see it, before their client sends the request for login.php.

     

    Or another case, like this:

    if ($condition_a) {
      header ('Location: a.php');
    }
    if ($condition_b) {
      header ('Location: b.php');
    }
    

    Suppose $condition_a and $condition_b are true, this won't do at all what you might expect by looking at the code.

  8. That code assumes that you're after a string, 'html', which isn't the case, or you wouldn't be using strip_tags.

     

    Your best bet is probably a regular expression hack, like this:

    $strCart = preg_replace ('/<[^>]*>/', ':', $strCart);

    You might need to escape the < and > in the regex, I can't remember.

  9. 1. You should check that the file has actually been uploaded first before you try to move it, e.g. is_uploaded_file.

    2. The above is failing because you are sending through a plain text form with no files attached, try: <form enctype="multipart/form-data" ...>

    3. You need to be sure that the user that the script runs as (quite often 'nobody', depending on the server's configuration) has permissions for the directory you're trying to store the file in.

  10. If the image won't open as the type that its extension suggests, you could try loading it using the functions for the other types, just in case the extension is wrong.

     

    You should probably do some kind of sanity check to see that the URL isn't a 404, unless you're 100% certain it's there.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.