![]() |
Highlight and link function names inside code
Here's a nice idea I got from another site, which highlights all function names in PHP code and links to their documentary. In this hack the functions are linked to PHP.NET's docs.
Needless to add this is perfect for sites that deal with PHP coding. :) Demo: Code:
if(!$dohtml) { // kill any rogue html code To install this hack download the attached file (linkfuncs.hack.php), upload to your /admin folder and use vbHacker. Have fun! :D |
Thats great, i saw it on evilwalrusdotcom. Great addition, thanks :up:
|
Yup, that's where I saw it too! Although they are using their own docs for the functions.
|
Well I see you're using it here. I have a complaint about this hack being used here.
Sometimes people post code here that is part of a hack. I like to keep local text files of hack instructions so that I can have a record of everything I've done, and can quickly re-apply each hack after a vB upgrade without having to search all over the forums for every hack I want. So when someone posts code directly in a message, I have to copy that and put it in a text file myself. The problem is that some editors, if you copy a hyperlink into it, will spell out the full URL of the link. For example, WordPad. I normally use Notepad on my Win2k computer, but for reasons which don't matter here, lately I've been having to access the Internet from my parents' computer, which only has WinMe on it, and the Notepad on WinMe sucks (it doesn't recognize any of the standard keyboard shortcuts and the search feature is limited, too). So I'm kind of forced to use WordPad here as my text editor, and even if you start a new document in text mode, if you paste anything with formatting into the window it still keeps the formatting, it just takes the formatting away when you save it as a text file. The problem is that if I try to copy, for example, this: PHP Code:
PHP Code:
Aside from all that, your hack didn't even work right for the example I just posted. I guess it just saw date( and assumed it was a PHP function? But it's not. It's vbdate(, a custom vB-only function. Perhaps there should be a way for a user (like me) to turn this feature off. I don't need it and won't use it, and it's just going to get in my way. I don't really see it being used very much in general, anyway; at least for me, when I'm getting code out of these forums is not the time I want to know what a specific function does. It's when I'm editing code later on that I might want to know what something does. Just my 2?. :) |
I just installed it with no problems, great hack firefly!
|
Quote:
|
a) The bug where vbdate() is parsed as date() and unlink() is parsed as link() should be fixed now.
Code:
unlink($bob); |
Done. Feel free to turn this off in your options.
|
Uploaded a vbHacker version. :)
|
nice hack!
|
i have it where members can enable and disable it in options but for some reason, even if you disable it, it still shows, heres the code
[php] if ($bbuserinfo[userid]==0 or $bbuserinfo[showfunclinks]==1) { /* Highlight function names in [php] */ $allfuncs = get_defined_functions(); $searches = array(); $replaces = array(); foreach ($allfuncs['internal'] as $name) { $searches[] = "/([^a-z])$name(<\/font><font color=\"" . ini_get('highlight.keyword') . "\">){0,1}( {0,1})\(<\/font>/i"; $replaces[] = "\\1<a href=\"http://www.php.net/$name\" target=\"_blank\">$name</a>\\2\\3(</font>"; } $buffer = preg_replace($searches, $replaces, $buffer); /* end Highlight function names in PHP Code:
|
Make sure $bbuserinfo is global in that function.
|
Hmm, it got rid of the links but the highlighting is still there and it shows ?> at the end of the php code
|
also the ?> if its enabled and some links arent linked as they do in the code bbcode
|
heres my php function
[php] // ###################### Start phphighlite ####################### function phphighlite($code) { //PHP 4 only global $bbuserinfo; if (floor(phpversion())<4) { $buffer=$code; } else { $code = str_replace("<br>", "", $code); $code = str_replace("<br />", "", $code); $code = str_replace(">", ">", $code); $code = str_replace("<", "<", $code); $code = str_replace("&", "&", $code); $code = str_replace('$', '\$', $code); $code = str_replace('\n', '\\\\n', $code); $code = str_replace('\r', '\\\\r', $code); $code = str_replace('\t', '\\\\t', $code); $code = stripslashes($code); if (!strpos($code,"<?") and substr($code,0,2)!="<?") { $code="<?\n".trim($code)."\n?>"; $addedtags=1; } ob_start(); $oldlevel=error_reporting(0); highlight_string($code); error_reporting($oldlevel); $buffer = ob_get_contents(); ob_end_clean(); if ($addedtags) { $openingpos = strpos($buffer,'<?'); $closingpos = strrpos($buffer, '?'); $buffer=substr($buffer, 0, $openingpos).substr($buffer, $openingpos+5, $closingpos-($openingpos+5)).substr($buffer, $closingpos+5); } $buffer = str_replace(""", "\"", $buffer); } if ($bbuserinfo[userid]==0 or $bbuserinfo[showfunclinks]) { /* Highlight function names in [php] */ $allfuncs = get_defined_functions(); $searches = array(); $replaces = array(); foreach ($allfuncs['internal'] as $name) { $searches[] = "/([^a-z])$name(<\/font><font color=\"" . ini_get('highlight.keyword') . "\">){0,1}( {0,1})\(<\/font>/i"; $replaces[] = "\\1<a href=\"http://www.php.net/$name\" target=\"_blank\">$name</a>\\2\\3(</font>"; } $buffer = preg_replace($searches, $replaces, $buffer); /* end Highlight function names in PHP Code:
|
any one know whats wrong?
|
^bump^
|
This is strange. For some reason I don't see this in my options panel.
Show links to function names in code? I installed the exact same version you have here. :confused: Quote:
|
Quote:
|
All times are GMT. The time now is 06:56 PM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|