Jump to content

How to use show_source()?


jdock1

Recommended Posts

Yall are probably laughin at me.

 

I am such a noob at php but learning fast.

 

Im trying to discover the show_source() function, but dont know how to implement it.

 

I tried just putting show_source() in the php code, but that didnt do anything.

 

Then, I tried echo "show_source()";

 

Now, im trying stuff like <a href="<?php show_source()?>" in the HTML

 

How the hell do I use this!? :D

 

Link to comment
Share on other sites

Well, what exactly are you trying to use it for? You know, it's for getting the source of a file, right?

 


$var = show_source(__FILE__);

echo $var;

 

If you're trying to get the "actual" source-code of a file, try file_get_contents() instead.

 

IE:

 

$var = file_get_contents('http://google.com');

echo '<textarea cols=10 rows=20>' . $var . '</textarea>';

 

*I added the textarea, just so you can see what it actually displays; otherwise, it would have just shown a knock-off of google. :P

Link to comment
Share on other sites

Well, what exactly are you trying to use it for? You know, it's for getting the source of a file, right?

 


$var = show_source(__FILE__);

echo $var;

 

If you're trying to get the "actual" source-code of a file, try file_get_contents() instead.

 

IE:

 

$var = file_get_contents('http://google.com');

echo '<textarea cols=10 rows=20>' . $var . '</textarea>';

 

*I added the textarea, just so you can see what it actually displays; otherwise, it would have just shown a knock-off of google. :P

 

Thanks bro, but I still cant figure it out.

 

Im trying to make a link on the php page that has the anchor "view php source" where they can, of course, click it and get the php source.

 

Thanks for the help bro

Link to comment
Share on other sites

Oh, well that's a completely different story. Neither of those will work for you. At least, not with the .php extension and <?php/?> tags (as file_get_contents renders what the server renders, so if  the server can't recognize the php to parse, file_get_contents will display the php).

 

Display the current PHP's source, would be a little more complicated. I would say the best way to do it, would be to open the file for reading, then echo out the contents in a textarea.

 

Maybe like so:

 

$filename = "CURRENT FILE HERE";
$h = fopen ($filename, "r");
$contents = fread ($h, filesize($filename));
fclose ($h);

echo '<textarea cols=10 rows=20>' . $contents . '</textarea>';

 

See if that works... (don't forget to specify the file where I put "CURRENT FILE HERE")

Link to comment
Share on other sites

Or you can do what lil jerk says, but instead of putting it into a text area, output it to the screen.

 

consider the following

$filename = "CURRENT FILE HERE";
$h = fopen ($filename, "r");
$contents = fread ($h, filesize($filename));
fclose ($h);

$contents = htmlentities($contents);//this function takes any < and > and converts them to their entities so instead of being executed by the browser, they are shown on the screen
echo $contents;

 

that will show the contents of a page

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.