News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Error in PHP... Can't see it.

Started by [SAP]Francis, July 01, 2008, 10:57:16 AM

Previous topic - Next topic

[SAP]Francis

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?

Vehicles Forum

Founded By Francis Morissette

winrules

I think the problem is right here:
                     \'\'\'
It should be:
                     \'\\\'\'


winrules
SMF Developer
               
My Mods
Please do not PM me for support.


[SAP]Francis

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!

Vehicles Forum

Founded By Francis Morissette

winrules

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:
\'\\\'\'


winrules
SMF Developer
               
My Mods
Please do not PM me for support.


[SAP]Francis

#4
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

Vehicles Forum

Founded By Francis Morissette

winrules

It was used in two places; you'll have to change both of them.


winrules
SMF Developer
               
My Mods
Please do not PM me for support.


[SAP]Francis

#6
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&#039;s i = %d", i);
    }
    return true;
}


The problem is the "&#039;s i = %d", i);" thing.
Any help?

Vehicles Forum

Founded By Francis Morissette

[SAP]Francis

Okay, no-one can help eh? Come on, guys.... This ain't impossible. I guess :(

Vehicles Forum

Founded By Francis Morissette

[SiNaN]

What is the actual error and your code?
Former SMF Core Developer | My Mods | SimplePortal

niko

It's because of html encoded chars. They are encoded as &#xx; So you have to make sure # isn't prefixed by "&" before replacing.
Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

[SAP]Francis


Vehicles Forum

Founded By Francis Morissette

[SAP]Francis

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&#039;s i = %d", i);
    }
    return true;
}


The problem is the "&#039;s i = %d", i);" thing.
Any help?

Vehicles Forum

Founded By Francis Morissette

niko

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
Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

[SAP]Francis

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 "# "

Vehicles Forum

Founded By Francis Morissette

niko

Try this

                     \'~[^&]#(.+?)\<br \/>~is\',
Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

[SAP]Francis

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,
),

?>

Vehicles Forum

Founded By Francis Morissette

[SAP]Francis

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?

Vehicles Forum

Founded By Francis Morissette

niko

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.
Websites: Madjoki || (2 links retracted by team, links out of date and taken over.)
Mods: SMF Arcade, Related topics, SMF Project Tools, Post History

WIP Mods: Bittorrent Tracker || SMF Wiki

Advertisement: