Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Displaying PHP Code

    How would u display PHP Coding on a page

    like you've got on here?

    PHP Code:
    Like this 

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    A nice simple way would be to use view-source("page.php")

  • #3
    New Coder
    Join Date
    Mar 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm, could try that

    but is there a way 2 display wot i type in myself? not display a ceratin page

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Only way I can think is to use str_replace, like

    $string = str_replace("<?php","<font color='blue'>&amp;lt;?php</font>",$string);

  • #5
    New Coder
    Join Date
    Mar 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how would i then use that 2 display though?

    btw, view-source didnt work, came up wiv an error. searched for it on PHP.net & couldnt find it. cheers ne way

  • #6
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    $string would be the info that you want highlighted, for example

    PHP Code:
    $string = "<?php echo "Yak"?>";
    // now go through the string and highlight various parts
    $string = str_replace("<?php","<font color='blue'>&amp;lt;?php</font>",$string);
    $string = str_replace("
    echo","<font color='orange'>echo</font>",$string);

    echo $string;
    Obviously there'll need more work on it, like reg exp being used on different keywords, but you get the idea, i hope

  • #7
    New Coder
    Join Date
    Mar 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    right... well i pasted that code straight in 2 see wot it comes up wiv on my page & it came up wiv this....

    Parse error: parse error, unexpected T_STRING in /home/gtaonet/public_html/community/mysql/basic.php on line 69

    which is this line:

    $string = "<?php echo "Yak"; ?>";

    u know y?

    i get the feeling im jumping straight in2 deep water & drwowning

    btw.... the site can be found here http://community.gtao.net

  • #8
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    oops, yeah I know, change "Yak" to 'Yak'

  • #9
    New Coder
    Join Date
    Mar 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    lol, there we go, works now

    so from that i should be ok? but u reckon i should look up reg exp? wot does that do exactly?

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    What I gave you will be the very basics, reg exp would highlight things properlylike echo "dfdfsf" would only result in echo " " being highlighted one color and the dfdfsf being in another colour, you can't do that with str_replace. I'd show an example of reg exp, but I hate it and don't know it that well

  • #11
    New Coder
    Join Date
    Mar 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    k, fair enough

    ill have a look 4 it then

    cheers 4 the help

  • #12
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $str = '<?php echo 'blat'; // comment ?>';

    $disp_str = highlight_string($str);
    echo $disp_str;
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #13
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Ooh, never knew about that one Thought there must've been an easier way

  • #14
    New Coder
    Join Date
    Mar 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah, that works pretty much

    but it so small i cant read it, just see the colours

    how would i change the font size?

  • #15
    New Coder
    Join Date
    Mar 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    not 2 worry, i figured that bit out

    the only prob i have now is that it wont display things like

    $name

    well ne thing wiv $ in front of it

    how do i get round that?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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