jdock1 Posted April 24, 2009 Share Posted April 24, 2009 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!? Quote Link to comment Share on other sites More sharing options...
alphanumetrix Posted April 24, 2009 Share Posted April 24, 2009 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. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 24, 2009 Share Posted April 24, 2009 You can always read the php manual section to learn how to use a php function - http://php.net/highlight_file Quote Link to comment Share on other sites More sharing options...
jdock1 Posted April 24, 2009 Author Share Posted April 24, 2009 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. 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 Quote Link to comment Share on other sites More sharing options...
alphanumetrix Posted April 24, 2009 Share Posted April 24, 2009 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") Quote Link to comment Share on other sites More sharing options...
mikesta707 Posted April 24, 2009 Share Posted April 24, 2009 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 Quote Link to comment Share on other sites More sharing options...
jdock1 Posted April 24, 2009 Author Share Posted April 24, 2009 Thanks!! Thats all I needed Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.