I have this in Subs.php which is supposed to highlight the PAWN syntax in the [pawn] tags.:
Quote[php]array(
'tag' => 'pawn',
'type' => 'unparsed_content',
'content' => '<div class="codeheader"><a href="http://www.compuphase.com/pawn/pawn.htm" title="More infos on PAWN language">PAWN</a> Code:</div><div class="code">' . ($context['browser']['is_gecko'] ? '<pre style="margin-top: 0; display: inline;">$1</pre>' : '$1') . '</div>',
'validate' => create_function('&$tag, &$data, $disabled', '
global $context;
if (!isset($disabled[\'pawn\']))
{
$data = str_replace(
array(
\'public\',
\'return\',
\'sizeof\',
\'switch\',
\'true\',
\'false\',
\'if\',
\'new\',
\'else\',
\'for(\',
\'while\',
\'(\',
\')\',
\'[\',
\']\',
\'{\',
\'}\',
\'\'\'
),
array(
\'<span style="color: blue;">public</span>\',
\'<span style="color: blue;">return</span>\',
\'<span style="color: blue;">sizeof</span>\',
\'<span style="color: blue;">switch</span>\',
\'<span style="color: blue;">true</span>\',
\'<span style="color: blue;">false</span>\',
\'<span style="color: blue;">if</span>\',
\'<span style="color: blue;">new</span>\',
\'<span style="color: blue;">else</span>\',
\'<span style="color: blue;">for</span>(\',
\'<span style="color: blue;">while</span>\',
\'<span style="color: black;">(</span>\',
\'<span style="color: black;">)</span>\',
\'<span style="color: black;">[</span>\',
\'<span style="color: black;">]</span>\',
\'<span style="color: black;">{</span>\',
\'<span style="color: black;">}</span>\',
\'|||\'
), $data);
$data = preg_replace(
array(
\'~#(.+?)\<br \/>~is\',
\'~\/\/(.+?)\<br \/\>~i\',
\'~\/\*(.+?)\*\/~i\'
),
array(
\'<span style="color: blue;">#$1<br /></span>\',
\'<span style="color: green;">//$1<br /></span>\',
\'<span style="color: green;">/*$1*/</span>\'
), $data);
$data = str_replace(\'|||\', \'\'\', $data);
// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
elseif (!$context[\'browser\'][\'is_gecko\'])
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
}'), // Line 1480
'block_level' => true,
),[php]
With thoses errors in the header:
QuoteParse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/gtasam/public_html/irc/forums/Sources/Subs.php(1480) : runtime-created function on line 28
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/gtasam/public_html/irc/forums/Sources/Subs.php(1480) : runtime-created function on line 28
What and where is my problem?
I think the problem is right here:
\'\'\'
It should be:
\'\\\'\'
Quote from: winrules on July 01, 2008, 11:09:50 AM
I think the problem is right here:
\'\'\'
It should be:
\'\\\'\'
No, cause it is to match this:
Hello world
's!
Not this:
Hello world\'s!
You have to double escape the string. The code you want to use (if it was not already inside a string) is this:'\''
You have to escape everything in that, which gets you this:
\'\\\'\'
Still the same error with that code:
<?php
array(
'tag' => 'pawn',
'type' => 'unparsed_content',
'content' => '<div class="codeheader"><a href="http://www.compuphase.com/pawn/pawn.htm" title="More infos on PAWN language">PAWN</a> Code:</div><div class="code">' . ($context['browser']['is_gecko'] ? '<pre style="margin-top: 0; display: inline;">$1</pre>' : '$1') . '</div>',
'validate' => create_function('&$tag, &$data, $disabled', '
global $context;
if (!isset($disabled[\'pawn\']))
{
$data = str_replace(
array(
\'public\',
\'return\',
\'sizeof\',
\'switch\',
\'true\',
\'false\',
\'if\',
\'new\',
\'else\',
\'for(\',
\'while\',
\'(\',
\')\',
\'[\',
\']\',
\'{\',
\'}\',
\'\'\'
),
array(
\'<span style="color: blue;">public</span>\',
\'<span style="color: blue;">return</span>\',
\'<span style="color: blue;">sizeof</span>\',
\'<span style="color: blue;">switch</span>\',
\'<span style="color: blue;">true</span>\',
\'<span style="color: blue;">false</span>\',
\'<span style="color: blue;">if</span>\',
\'<span style="color: blue;">new</span>\',
\'<span style="color: blue;">else</span>\',
\'<span style="color: blue;">for</span>(\',
\'<span style="color: blue;">while</span>\',
\'<span style="color: black;">(</span>\',
\'<span style="color: black;">)</span>\',
\'<span style="color: black;">[</span>\',
\'<span style="color: black;">]</span>\',
\'<span style="color: black;">{</span>\',
\'<span style="color: black;">}</span>\',
\'|||\'
), $data);
$data = preg_replace(
array(
\'~#(.+?)\<br \/>~is\',
\'~\/\/(.+?)\<br \/\>~i\',
\'~\/\*(.+?)\*\/~i\'
),
array(
\'<span style="color: blue;">#$1<br /></span>\',
\'<span style="color: green;">//$1<br /></span>\',
\'<span style="color: green;">/*$1*/</span>\'
), $data);
$data = str_replace(\'|||\', \'\\\'\', $data);
// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
elseif (!$context[\'browser\'][\'is_gecko\'])
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
}'), // Line 1480
'block_level' => true,
),
?>
Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ')' in /home/gtasam/public_html/irc/forums/Sources/Subs.php(1480) : runtime-created function on line 28
^--------- Header
It was used in two places; you'll have to change both of them.
Right, new error:
This:
[pawn]if(!strcmp(cmdtext, "/test", true))
{
for(new i=0; i<MAX_PLAYERS; i++)
{
printf("/test's i = %d", i);
}
return true;
}[/pawn]
Gives exactly this:
PAWN Code:
if(!strcmp(cmdtext, "/test", true))
{
for(new i=0; i<MAX_PLAYERS; i++)
{
printf("/test's i = %d", i);
}
return true;
}
The problem is the "'s i = %d", i);" thing.
Any help?
Okay, no-one can help eh? Come on, guys.... This ain't impossible. I guess :(
What is the actual error and your code?
It's because of html encoded chars. They are encoded as &#xx; So you have to make sure # isn't prefixed by "&" before replacing.
And... How? :P
Quote from: [SiNaN] on August 18, 2008, 08:31:47 AM
What is the actual error and your code?
Quote from: [SAP]Francis on July 01, 2008, 03:58:25 PM
Right, new error:
This:
[pawn]if(!strcmp(cmdtext, "/test", true))
{
for(new i=0; i<MAX_PLAYERS; i++)
{
printf("/test's i = %d", i);
}
return true;
}[/pawn]
Gives exactly this:
PAWN Code:
if(!strcmp(cmdtext, "/test", true))
{
for(new i=0; i<MAX_PLAYERS; i++)
{
printf("/test's i = %d", i);
}
return true;
}
The problem is the "'s i = %d", i);" thing.
Any help?
Quote from: [SAP]Francis on August 18, 2008, 11:49:44 AM
And... How? :P
Changis this preg replace
\'~#(.+?)\<br \/>~is\',
to something like:
\'~([^&])#(.+?)\<br \/>~is\',
should work
Now, this:
Quote[pawn]#define lol
#
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/test", true))
{
for(new i=0; i<MAX_PLAYERS; i++)
{
printf("/test's i = %d", i); //test
#if defined lol
test; // lol
#endif
}
return true;
}
if(!strcmp(cmdtext, "/test", true))
{
for(new i=0; i<MAX_PLAYERS; i++)
{
printf("/test's i = %d", i); //test
#if defined lol
test; // lol
#endif
}
return true;
}
if(!strcmp(cmdtext, "/test", true))
{
for(new i=0; i<MAX_PLAYERS; i++)
{
printf("/test's i = %d", i); //test
#if defined lol
test; // lol
#endif
}
return true;
}
return 0;
}[/pawn]
In the output of this, all the lines contening "#" in it will get erased and replaced by "# "
Try this
\'~[^&]#(.+?)\<br \/>~is\',
Woot, it worked. But, focus on the first line; it's not working for the first:
http://gta-sa-mp.com/irc/forums/index.php?topic=16.0
This is the code:
<?php
array(
'tag' => 'pawn',
'type' => 'unparsed_content',
'content' => '<div class="codeheader"><b><u><a href="http://www.compuphase.com/pawn/pawn.htm" title="More infos on PAWN language">PAWN</a></u> Code:</b></div><div class="code">' . ($context['browser']['is_gecko'] ? '<pre style="margin-top: 0; display: inline;">$1</pre>' : '$1') . '</div>',
'validate' => create_function('&$tag, &$data, $disabled', '
global $context;
if (!isset($disabled[\'pawn\']))
{
$data = str_replace(
array(
\'public\',
\'return\',
\'sizeof\',
\'switch\',
\'true\',
\'false\',
\'if\',
\'new\',
\'else\',
\'for(\',
\'while\',
\'(\',
\')\',
\'[\',
\']\',
\'{\',
\'}\',
\'\\\'\'
),
array(
\'<span style="color: blue;">public</span>\',
\'<span style="color: blue;">return</span>\',
\'<span style="color: blue;">sizeof</span>\',
\'<span style="color: blue;">switch</span>\',
\'<span style="color: blue;">true</span>\',
\'<span style="color: blue;">false</span>\',
\'<span style="color: blue;">if</span>\',
\'<span style="color: blue;">new</span>\',
\'<span style="color: blue;">else</span>\',
\'<span style="color: blue;">for</span>(\',
\'<span style="color: blue;">while</span>\',
\'<span style="color: black;">(</span>\',
\'<span style="color: black;">)</span>\',
\'<span style="color: black;">[</span>\',
\'<span style="color: black;">]</span>\',
\'<span style="color: black;">{</span>\',
\'<span style="color: black;">}</span>\',
\'|||\'
), $data);
$data = preg_replace(
array(
\'~[^&]#(.+?)\<br \/>~is\',
\'~\/\/(.+?)\<br \/\>~i\',
\'~\/\*(.+?)\*\/~i\'
),
array(
\'<span style="color: blue;">#$1<br /></span>\',
\'<span style="color: green;">//$1<br /></span>\',
\'<span style="color: green;">/*$1*/</span>\'
), $data);
$data = str_replace(\'|||\', \'\\\'\', $data);
// Older browsers are annoying, aren\'t they?
if ($context[\'browser\'][\'is_ie4\'] || $context[\'browser\'][\'is_ie5\'] || $context[\'browser\'][\'is_ie5.5\'])
$data = str_replace("\t", "<pre style=\"display: inline;\">\t</pre>", $data);
elseif (!$context[\'browser\'][\'is_gecko\'])
$data = str_replace("\t", "<span style=\"white-space: pre;\">\t</span>", $data);
}'),
'block_level' => true,
),
?>
Actually, I think that it's because it checks if <br /> is on the line. While in the source, it is a <br>.
Anyway to fix this?
Try replacing this:
$data = preg_replace(
array(
\'~[^&]#(.+?)\<br \/>~is\',
\'~\/\/(.+?)\<br \/\>~i\',
\'~\/\*(.+?)\*\/~i\'
),
array(
\'<span style="color: blue;">#$1<br /></span>\',
\'<span style="color: green;">//$1<br /></span>\',
\'<span style="color: green;">/*$1*/</span>\'
), $data);
with
$data = preg_replace(
array(
\'~([^&]|^)#(.+?)\<br \/>~is\',
\'~\/\/(.+?)\<br \/\>~i\',
\'~\/\*(.+?)\*\/~i\'
),
array(
\'<span style="color: blue;">#$2<br /></span>\',
\'<span style="color: green;">//$1<br /></span>\',
\'<span style="color: green;">/*$1*/</span>\'
), $data);
Since previous required there to be any character other than # at beginning.
It is <br /> but Firefox shows post-processed source.