Page 2 of 2

Posted: Sat Jun 19, 2004 2:07 pm
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;
					}
				}
?>

Posted: Sat Jun 19, 2004 5:19 pm
by McGruff
Try preg_quote() not addslashes.

Posted: Wed Jun 23, 2004 6:06 pm
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/]/

Posted: Thu Jun 24, 2004 10:58 am
by John Cartwright
does no one love me?