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

Thread: How do you style php code?

  1. #1
    Join Date
    Aug 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How do you style php code?

    Maybe a very lame question, though I haven't a clue..

    I've got my form to work, though would like to style it if poss, with a bold title, coloured heading.

    Can you do this?

    this is the form if it helps
    http://www.clippergems.com/who.html

    thanks very much guys,
    Elliot

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You don't style the PHP code, you style the HTML it outputs. Just link to a CSS file as you would any HTML page.

    P.S.
    "What's is a ClipperGem?"
    should be
    "What is a ClipperGem?"
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Aug 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Whoops! luckily this site isn't live yet....
    First thing I did was changed the top nav. I'll be extra thourough before I let the public see it

    When you said just style the HTML it outputs, should I be styling the HTML within the <?php ?> tags with whatever I need like so.....?

    <?php
    <h2>Title</h2>
    <p class="blue">text</p>
    ?>


    thanks very much mate

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Yep, more or less. Obviously you wouldn't put HTML directly in the PHP tags as you did there, though. I'm presuming that was an example.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Aug 2005
    Posts
    63
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I'm presuming that was an example
    actually I'm a bit confused with this. Could you please give me an example, as my example was in fact my interpretation, which is wrong . Sorry mate

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    <?php
    # do PHP stuff
    echo("<p class=\"blue\">");
    ?>
    </p>
    <p class="red">
    </p>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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

    Default

    How would this work if I wanted to style variables? So for example, the variables would be bold within a paragraph that has the variables in it when it is printed?

  8. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    The simplist way I'm think of would be put span tags around them and either style each or make a class if they are all the same styles.

    example
    <style type="text/css">
    .bold {
    font-weight:bold;
    }
    </style>
    <?php
    $name = "You didn't enter a name";
    some other php stuff
    if ($name <> "You didn't enter a name" ) {
    echo "$something <h1> Your name is: <span class=\"bold\">$name</span>";
    }
    else {
    echo "<span class=\"bold\">$name</span>";
    }

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP ONLY generates html. A valid PHP page does NOT need to contain PHP tags at all, in fact. It can just be normal html, without any added PHP.

    Between PHP tags you only have PHP code. Outside of the PHP tags you have normal HTML, Javascript, CSS, etc.

    If you need to output HTML, etc., from within PHP tags, do so using echo or another method (depending on how you PHP works).

    Look at Twey's example above. It shows both methods.

    You can either output all the text directly from within PHP (the post above mine) or you can just output parts, like this:
    <span>Some text <b><?php echo $boldtext; ?></b> more text </span>
    Likely, <b> is not the best method in HTML, but that has nothing to do with the PHP code.

    Please review the information here, if any of this is not clear.
    http://dynamicdrive.com/forums/showthread.php?t=25847

    In general you need to start thinking of PHP as just an html generator, so generate html however you would like, using PHP as a tool to output text how and where you should like.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Oct 2009
    Posts
    31
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Erm why don't you use highlight_string() ?

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
  •