Tutorial Script

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!

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

just adding another problem.... I'm getting the invalid char error because of my quotations... easily fixed by addslashes / stripslashes right?

wrong...

for some reason

I am still getting this with it on

Code: Select all

<?php
if($submit) //If submit is hit

{

    mail(
Warning: Unexpected character in input: '' (ASCII=92) state=1 in C:apache2triadhtdocsjcartonline.comhtmlincfunctions.php(14) : regexp code on line 7

Warning: Unexpected character in input: '' (ASCII=92) state=1 in C:apache2triadhtdocsjcartonline.comhtmlincfunctions.php(14) : regexp code on line 7
"youremailhere", $subject, $email, $comments);

}?>
?>
Notice this:

Code: Select all

<?php
"youremailhere", $subject, $email, $comments);
?>
which is only getting a slash on the second quotation

here is my code for processing the code..

Code: Select all

<?php
class tutorials {

				function phphighlight($rawcode,$view)
					{
					$rawcode = addslashes($rawcode);
					
					if ($view == "tutorial")
						{
						//$output = preg_replace("/\[ php]([^[]*)\[\/ php]/ime", 
						//				       "'<br><br><b>PHP:</b><table style="width: 100%; color: #000; background-color: #FFF; border: 2px solid #808080; font-size: 8pt;"><tr><td style="padding: 10px";>'.highlight_string('\\1',true).'</td></tr></table><br>'",
						//				       $rawcode);	  
						$output = preg_replace('|\[ php](.*?)\[ /php]|ise',"highlight_string('\\1',true)", $rawcode); 
						
						$output = preg_replace("/\[html]([^[]*)\[\/html]/ime", 
										       "'<b>HTML:</b><table style="width: 100%; color: #000; background-color: #FFF; border: 2px solid #808080; font-size: 8pt;"><tr><td style="padding: 10px";><html>'.highlight_string('\\1',true).'</html></td></tr></table><br>'",
										       $output);	  
						$output = preg_replace("/\[js]([^[]*)\[\/js]/ime", 
										       "'<br><br><b>Javascript:</b><table style="width: 100%; color: #000; background-color: #FFF; border: 2px solid #808080; font-size: 8pt;"><tr><td style="padding: 10px";>'.highlight_string('\\1',true).'</td></tr></table><br>'",
										       $output);	  												
						}
					else
						{
						$output = $rawcode;
						}
						
						
					$output = stripslashes(nl2br($output));
					echo $output;
					}
				}
?>
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Try preg_quote() not addslashes.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I still havn't gotten preg_quote to quite work :S ... any help is welcome..

but my main concern still is that I can't get the code to highlight like the forums... or like .phps extensions


EDIT**

While playing around with preg quote I tried escaping all special characters by using

Code: Select all

<?php
$output = preg_quote("\\+*?[^]$(){}=!<>|:",$rawcode);
?>
found in my function:

Code: Select all

<?php

class tutorials {

				function phphighlight($rawcode,$view)
					{

					$output = preg_quote("\\+*?[^]$(){}=!<>|:",$rawcode);
					
					if ($view == "tutorial")
						{				
						$output = preg_replace("/\[ php]([^[]*)\[\ /php]/ime", 
										       "'<br><br><b>PHP:</b><table style="width: 100%; color: #000; background-color: #FFF; border: 2px solid #808080; font-size: 8pt;"><tr><td style="padding: 10px";>'.highlight_string('\\1',true).'</td></tr></table><br>'",
										       $rawcode);	  
						//$output = preg_replace('|\[ php](.*?)\[ /php]|ime',"highlight_string('\\1',true)", $rawcode); 
						
						$output = preg_replace("/\[html]([^[]*)\[\/html]/ime", 
										       "'<b>HTML:</b><table style="width: 100%; color: #000; background-color: #FFF; border: 2px solid #808080; font-size: 8pt;"><tr><td style="padding: 10px";><html>'.highlight_string('\\1',true).'</html></td></tr></table><br>'",
										       $output);	  
						$output = preg_replace("/\[js]([^[]*)\[\/js]/ime", 
										       "'<br><br><b>Javascript:</b><table style="width: 100%; color: #000; background-color: #FFF; border: 2px solid #808080; font-size: 8pt;"><tr><td style="padding: 10px";>'.highlight_string('\\1',true).'</td></tr></table><br>'",
										       $output);	  												
						}
					else
						{
						$output = $rawcode;
						}
						
						
					$output = stripslashes(nl2br($output));
					echo $output;
					}
				}

?>
this cause anything inside [ php] [ /php] to be highlighted in blue only >:| but if the code contains a [ or a ] is will not be highlighted and just will output

Code: Select all

&#1111;php ] echo "blah"; &#1111; /php]

How come the preg_quote isnt picking it up?
EDIT AGAIN *********

im stuck once again how will i prevent my [ php] and [ /php] from being changed to /[/php/]/ and /[/php/]/
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

does no one love me?
Post Reply