Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Display sourcecode on page

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Display sourcecode on page

Postby p3x » Mon Mar 10, 2003 11:04 am

Hello, I would like to know how to display sourcecode (HTML and php) on a webpage without it being executed (like the option they have on this form for example). Any help would be welcome :)

P3x
p3x
New php-forum User
New php-forum User
 
Posts: 17
Joined: Mon Mar 03, 2003 10:53 am

Postby SmartAssDan » Mon Mar 10, 2003 11:26 am

Code: Select all
<?php
// Get a file into an array.  In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file ('http://www.example.com/');

// Loop through our array, show html source as html source; and line numbers too.
foreach ($lines as $line_num => $line) {
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}

// Another example, let's get a web page into a string.  See also file_get_contents().
$html = implode ('', file ('http://www.example.com/'));
?>




found that under the "file" function in the php manual. enjoy!
SmartAssDan
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun Mar 09, 2003 4:33 pm

Postby SmartAssDan » Mon Mar 10, 2003 11:27 am

oh, and i'm not sure, but i think that code would execute the php and return the resulting html... but again, not sure.
SmartAssDan
New php-forum User
New php-forum User
 
Posts: 5
Joined: Sun Mar 09, 2003 4:33 pm

Postby pootergeist » Mon Mar 10, 2003 12:27 pm

for html use <xmp> any html here is shown </xmp>
tp preserve formatting <pre><xmp> .........</xmp></pre>

for php - you might like syntax highlighted output

$str = '<?php echo \'rabbit\'; ?>';
$high_str = highlight_string($str);
echo $high_str;

also used - highlight_file( filename )

both highlight_string and highlight_file should contain both opening and closing <?php ?> tags.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK

Postby Xerpher » Mon Mar 10, 2003 12:52 pm

Code: Select all
<?php show_source("filename.ext"); ?>

This will show the full source code of any local file, if you try to do it to a remote file via HTTP you will get the source of the its parsed content, so you won't see actual php code remotely.
Xerpher
New php-forum User
New php-forum User
 
Posts: 164
Joined: Tue Aug 27, 2002 8:25 pm
Location: Ontario, Canada

Postby Redcircle » Mon Mar 10, 2003 9:35 pm

you can also rename the file to an extension that the parser will not process. Using .phps will also add proper highlighting.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Thank you!

Postby p3x » Tue Mar 11, 2003 2:37 am

Thanks for all the replies! I made a combination of all the suggestions and it works beatifully now :) thanks again

:lol:
P3x
p3x
New php-forum User
New php-forum User
 
Posts: 17
Joined: Mon Mar 03, 2003 10:53 am


Return to PHP coding => General

Who is online

Users browsing this forum: Majestic-12 [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.