PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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.
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.
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
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.
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
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.
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