1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Printing errors in PHP

Discussion in 'PHP' started by technobuddy, May 29, 2011.

  1. technobuddy

    technobuddy New Member

    Joined:
    May 29, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi friends,
    I am new in this website, and posting my first post. This is all about PHP , which is recently being most popular server side scripting language. I new some people who have some problem in printing or echo in PHP. The problem is

    echo "HI how are u" //This is OK
    echo "<style="color:blue">hi how are u my friends?</style>";/*Parse error: syntax

    error, unexpected T_STRING, expecting ',' or ';..............*/

    people are confused what is happing ???? but the main problem is using "" in between the 2 " of echo so what will be the ans???? come on there is solution here it is:
    echo "<style=\"color:blue\">hi how are u my friends?</style>";// use the\ to indicate the " as unique one.
    I think this will help my friends. So for now
    Bye bye :charming:
     
  2. pein87

    pein87 New Member

    Joined:
    Aug 6, 2010
    Messages:
    173
    Likes Received:
    47
    Trophy Points:
    0
    Occupation:
    Web Dev
    Location:
    Limbo
    Code:
    echo "<style=[COLOR="Red"]"[/COLOR]color:blue[COLOR="Red"]"[/COLOR]>hi how are u my friends?</style>";
    Your not escaping the double quotes inside the double quotes. If your using double quotes and have other double quotes in side of it you need to escape it.

    PHP:
    echo "<style="color:blue">hi how are u my friends?</style>";
    Should be

    PHP:
    echo "<style=\"color:blue\">hi how are u my friends?</style>";
    Also I might mention you need to change the style tag to a span tag because style tags aren't used in this manner unless this is xml and you'd probably use xstl for that instead of pure css.

    PHP:
    echo "<span style=\"color:blue\">hi how are u my friends?</span>";
    or you could just do this

    PHP:
    echo '<span style="color:blue">hi how are u my friends?</span>';
    for more on escaping strings check this out

    http://php.net/manual/en/language.types.string.php

    http://www.homeandlearn.co.uk/php/php7p7.html
     
    Last edited: Jun 1, 2011
    shabbir likes this.

Share This Page