Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: PHP Basics

  1. #1
    Join Date
    Jul 2003
    Posts
    424
    Rep Power
    0

    Default PHP Basics

    I am not a programmer, however I can read code. ironic eh? What it the newline character in php. I am just trying to read stuff from a table in a database, the information is retrieve but I need a new line after each row. Code enclosed. How can I put in a newline character in the higlighted line?

    <?php
    mysql_connect("localhost", "root", "new-password&quot or
    die("Could not connect: " . mysql_error());
    mysql_select_db("trial"

    $result = mysql_query("SELECT id, FirstNames FROM tbl_name"

    while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
    printf ("ID: %s Name: %s", $row{0}, $row[1]);
    }

    mysql_free_result($result);
    ?>

    The curly brakets shoud actually be suare brackets, but I think it is being resloved as an attribute on this site. Please substitute, if you noticed I had to modify this post.

  2. #2
    Join Date
    Jul 2002
    Posts
    818
    Rep Power
    0

    Default Re:PHP Basics

    "\n" on unix/linux, "\r\n" on windows.

  3. #3
    Join Date
    May 2003
    Posts
    137
    Rep Power
    0

    Default Re:PHP Basics

    By the Way....In Perl there is the chomp function that takes the variable and strips the newline character from it-entered from the user <STDIN>.

    Example:

    $variable1=test;
    chomp($variable1)

  4. #4
    Join Date
    May 2003
    Posts
    137
    Rep Power
    0

    Default Re:PHP Basics

    Is there an equivalent in PHP ?

  5. #5
    Join Date
    Jul 2002
    Posts
    818
    Rep Power
    0

    Default Re:PHP Basics

    Not to my knowledge, but it should be fairly easy to write one.

    <?
    $i=0;
    while ($i <= strlen($someString))
    {
    $cur = substr($someString, $i, 1);
    if ($cur == "\n&quot $cur = "";
    $newString= $newString . $cur;   
    $i++;
    }
    ?>

  6. #6
    Join Date
    Jul 2003
    Posts
    424
    Rep Power
    0

    Default Re:PHP Basics

    My webserver is running on Redhat Linux 9.0. I tried the \n but it made no difference.

    I used <br>\n instead, it worked fine.
    printf ("ID: %s Name: <br>\n"%s", $row{0}, $row[1]);

    I wonder what is for the tab character?


  7. #7
    Join Date
    Jul 2002
    Posts
    818
    Rep Power
    0

    Default Re:PHP Basics

    Now I see. What you wanted was a break in HTML output. If that's the case then all you need is the "<BR>". "\n" is used for console and file output, not for output to web pages.

    For tab you may have to use multiple "nbsp;" 'cause I can't think of a TAB character for HTML. I suggest you use tables though.

  8. #8
    Join Date
    Aug 2002
    Posts
    193
    Rep Power
    0

    Default Re:PHP Basics

    Yes, I agree with CKnight, don't try to use tabs it will throw out your layout. Use tables.

  9. #9
    Join Date
    Aug 2002
    Posts
    1,236
    Rep Power
    0

    Default Re:PHP Basics

    I really didn't stop to see what you were attempting. So excuse me if this is of no value to you.
    The nl2br function can convert newlines to <br> html tags.

    http://us4.php.net/manual/en/function.nl2br.php

    I know this will help someone.

  10. #10
    Join Date
    Aug 2002
    Posts
    1,236
    Rep Power
    0

    Default Re:PHP Basics

    you could use tabs in the pre tag

    <pre> This   is   an    example   that &nb sp; uses   tabs  &nb sp;
            &n bsp;within
          those &nb sp;     handy    pre tags</pre>

    As a general rule this probably isn't what you want though.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •