Page 1 of 8
[solved] php highlight function help
Posted: Sat Apr 07, 2007 7:36 am
by ziggy3000
Dont worry i already have my highlight function, and i know how to use it.
This was made by
Kai Sellgren
Function.php
edited: i don't feel like revealing this code forever... this problem is solved .
To use this you need to do this in your code
Code: Select all
<?php
include('function.php');
$code = '<?php phpinfo(); ?>';
hc($code,1,1);
?>
The problem is that i want to use this function just by typing
Can you do this by using php in the css file or what?
Posted: Sat Apr 07, 2007 9:07 am
by aaronhall
If you are trying to highlight a part of a string that will be enclosed in the <code> element, you can use
preg_replace_callback(). If you're asking if a browser can recognize those tags like HTML tags and call a PHP function, it's not possible, CSS or not. PHP code is parsed on the server side, and the resulting output (usually HTML) is returned to the web browser and parsed then by the browser. No PHP code is ever interpreted by the browser.
Posted: Sat Apr 07, 2007 9:18 am
by RobertGonzalez
You are going to need to set up something similar in style to a bbCode parser for this. You might have a look at the Wordpress plugin wp-syntax and how the implement the GeSHi highlighter. It is fairly simple as long as you are comfortable with regexp and callbacks.
Posted: Sat Apr 07, 2007 9:28 am
by ziggy3000
Everah, can you give me some links?
i dont use wordpress
and i dont especially use the GeSHi highlighter.(I hate the colors)
and aaronhall, can you setup the css file so it interprets php and then you can specify what color the comments, html tags php functions should be.
and then when you include the css file it transforms
Code: Select all
<code>
<?php
//comment
phpinfo();
?>
</code>
to
Code: Select all
<code>
<?php
//comment
phpinfo();
?>
</code>
Posted: Sat Apr 07, 2007 9:54 am
by aaronhall
The closest you can get is to wrap different portions of the to-be-highlighted code in spans with styles attached to them, e.g. <span class="php_comment">//asdfasdf</span>. If might be helpful for you to read an introductory CSS tutorial.
Also, geshi allows you to change the output's style via css.
Posted: Sat Apr 07, 2007 10:37 am
by ziggy3000
is there a really good introductory css crash course tutorial or CSS 101
i could really use it. and i really wouldnt like to write that much code, when i could use the hc function instead.
i was just asking if i could put php in a css file so it automatically converts comments, functions, and stuff without me typeing the html code
For example
on the page i want the higlighted code
i could have it like this
Code: Select all
<code class="php">
<?php
//comment
phpinfo();
?>
</code>
and the css file changes the colors and stuff.
Posted: Sat Apr 07, 2007 1:57 pm
by aaronhall
Simply put, no -- CSS doesn't have the facilities to conditionally highlight parts of a class. As for a tutorial, visit your favorite search engine.
Posted: Sat Apr 07, 2007 2:24 pm
by ziggy3000
even if you can use php in it?
Posted: Sat Apr 07, 2007 2:38 pm
by aaronhall
The HTML and CSS is what a PHP script would return or output to the browser... the browser then interprets that HTML/CSS to render the page. PHP is completely finished processing the file by the time the browser starts interpreting the html/css. Additionally, CSS doesn't have the same facilities PHP does to operate on strings. Again, have a look at an introductory CSS tutorial to get a better scope of the language.
I should have asked this before, but why are you trying to do this? There's probably a better (feasible) approach.
Posted: Sat Apr 07, 2007 4:51 pm
by ziggy3000
l o l i know how php works!!
i wanted to do this so my html code would look like
Code: Select all
<html>
//link to css file
<code type="php">//php code here</code>
</html>
and the css file uses the php function so it replaces
with a random 5 digit variable(in case i use it again on that page, if so i need it to be random)
and uses that same variable in the function. so it would replace the above code like so
Code: Select all
<html>
//link to css file
<code type="php">
<?php
$fivedigitvar = "//php code here";
hc($fivedigitvar,1,1);
?>
</code>
</html>
I want to do this so i wouldn't have to type as much in the code for my website
Posted: Sat Apr 07, 2007 5:01 pm
by aaronhall
Again, no, css has no facilities to manipulate strings on the fly, with or without PHP code in the CSS file.
Posted: Sat Apr 07, 2007 5:11 pm
by ziggy3000
ok

thanks for trying...
Posted: Sat Apr 07, 2007 9:19 pm
by ziggy3000
what if i want to create bbcode, so when i parse this
the parser will make it look like the way it does
here
Posted: Sat Apr 07, 2007 9:26 pm
by feyd
It's possible to do.
Posted: Sat Apr 07, 2007 9:50 pm
by ziggy3000
i want to use this
code
but i dont know how to use it. i asked there too(at the bottom), but no one's replied yet.
how should i call the function
or is there a better bbcode script? i am looking on google, and i cant find any "good" scripts