SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Beginner write \n,\r,\t,\b..

    I have my php generating html cod, and I want to be 'nice' when you are looking at the html page -> "view page source ". When I concatenate the \n,\r it just puts the characters like it is a part of the page.

    I have tried to eliminate this, with ob_start (), but it didn't work.

    Haw I can do this ?

    Thanks, cheers!

  2. #2
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can output special characters using double quotes around the string.

    PHP Code:
    echo "\t<div id=\"container\">\n",
    "\t\tThis is the content of the container.\n",
    "\t</div>"
    Or
    PHP Code:
    <?php
        $result 
    mysql_query('Select id, Name from Users order by Name ASC');
        while (
    $row mysql_fetch_array($result)) {
    ?>
        <div class="User">
            <a href="viewProfile/<?php echo $row['id']; ?>"><?php echo $row['Name']; ?></a>
        </div>
    <?
        
    }
    ?>
    FOR SALE: 1 set of morals, never used, will sell cheap

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!!

    It works!; I didn't new that the \n,\t... had to be interpreted by the php. when I changed the ' to " it worked just fine.

    Thanks allot !!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Location
    Bristol, England
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The key is to use double quote, and not single quotes. The following will output very different results:

    PHP Code:
    echo '\t<h1>Heading</h1>';

    echo 
    "\t<h1>Heading</h1>"

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Christopher, I have tested also the out put off your code, and now I understand, Thanks for the reply!


Bookmarks

Posting Permissions

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