Results 1 to 3 of 3

Thread: whats the ' for

  1. #1
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default whats the ' for

    PHP Code:
    <?php

    $money 
    30;
    $pet "Kitten";
    $new sprintf("It costs $%03.2f for a %s.\n",$money,$pet);
    $new2 sprintf("%[B][B][COLOR="Red"]'[/COLOR][/B][/B].-20s%3.2f",$pet,$money);
    echo 
    $new;
    echo 
    $new2;
     
    ?>
    I just don't understand what the ' is for. When you remove it, it treats the string literally. why is there only one though?
    Last edited by Snookerman; 07-29-2009 at 08:16 AM.

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    PHP Code:
    "%[b][b][color="Red"]'[/color][/b][/b].-20s%3.2f" 
    If you are talking about the single quote above, the entire string is not formed correctly, thus, I don't think there is any good reason there is only one.

    In the above, a string is starting with the first double quote and ending with the next, then restarting with the next double quote and ending again with the double quote after the f, in affect causing the word RED to not be included in the string at all.

    Also you said that removing the ' will treat the string literally. I don't believe this is the case. Using single quotes to enclose a string will cause the string to be treated literally. Using double quotes will cause variables and placeholders to be evaluated.

    If you are thinking something else, or I missed something, let me know.

  3. #3
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    I would agree that the single single-quote appears to be a typo and should be removed. It also seems that the double-quotes around the word RED need to be escaped, so "RED" is counted as part of your string, like so:
    PHP Code:
    <?php
    $new2 
    sprintf("%[B][B][COLOR=\"Red\"][/COLOR][/B][/B].-20s%3.2f",$pet,$money);
    ?>

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
  •