[php] functie werkt niet tussen quotes...

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
Ik ben dus bezig met een forum warbij een onderdeel is om de tags [] eruit te halen, nu wil ik met behulp van een functie in de replace sectie de PHP codes wijzigen.

Die replace zet ik uiteindelijk in een preg_replace() functie, maar het rare is dat het bij een voorbeeld -ergens van internet geplukt- wel werkt maar bij mij niet :(.

Nu heb ik dat zo gedaan:
PHP:
1
                $objects[] =    '$this->formatcode(\'\\1\')';


en in dat voorbeeld staat het er zo:

PHP:
1
                    '$this->colorphp(\'\\1\')',


Iemand die weet waarom mijn versie de functie niet laad en in het tweede voorbeeld wel?

Acties:
  • 0 Henk 'm!

  • Jurgle
  • Registratie: Februari 2003
  • Laatst online: 24-06 00:27

Jurgle

100% Compatible

Staat er bij dat voorbeeld niet meer bij (op vorige en volgende regels)? Jouw code eindigd nl op een ; en het voorbeeld op een ,

My opinions may have changed but not the fact that I am right ― Ashleigh Brilliant


Acties:
  • 0 Henk 'm!

  • Basszje
  • Registratie: Augustus 2000
  • Laatst online: 13:17

Basszje

Reisvaap!]

Ik zou voor de grap ook even de preg_replace erbij plaatsen. Dit is nogal een beperkt stukje :)

Beware of listening to the imposter; you are undone if you once forget that the fruits of the earth belong to us all, and the earth itself to nobody.


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
hehe, nou kijkik heb de array voor de preg_replace op een andere manier opgebouwd:
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$search = Array(
                    "~\[CODE](.+?)\[/CODE]~is",
                    "~\[CODE=(.+?)](.+?)\[/CODE]~is",
                    "~\[URL](.+?)\[/URL]~i",
                    "~\[URL=(http|ftp|https)://(.+?)](.+?)\[/URL]~i",
                    "~\[URL=(.+?)](.+?)\[/URL]~is",
                    "~\[IMG=(http|ftp|https)://(.+?)](.+?)\[/IMG]~i",
                    "~\[IMG=(.+?)](.+?)\[/IMG]~is",
                    "~\[IMG](.+?)\[/IMG]~is",
                    "~\\[EMAIL=([_a-z0-9-.]+@[a-z0-9-]+\.[a-z0-9-]+)](.+?)\[/EMAIL]~is",
                    "~\[QUOTE](.+?)\[/QUOTE]~is",
                    "~\[QUOTE=(.+?)](.+?)\[/QUOTE]~is"
                    );
                
                $objects   =    Array();
                $varCode   =    "\\1";
                $objects[] =    '$this->formatcode(\'\\1\')';
                $varCode   =    "\\2";
                $varTitle  =    " : \\1";
                $objects[] =    eval($this->template('OBJECTS_CODE'));
                $objects[] =    "<a target='_blank' href='\\1'>\\1</a>";
                $objects[] =    "<a target='_blank' href=\"\\1://\\2\">\\3</a>";
                $objects[] =    "<a target='_blank' href=\"http://\\1\">\\2</a>";
                $objects[] =    "[img]\"\\1://\\2\"[/img]";
                $objects[] =    "[img]'http://\\1'[/img]";
                $objects[] =    "[img]'\\1'[/img]";
                $objects[] =    "<a href=\"mailto:\\1\"> \\2 </a>";
                $varQuote  =    "\\1";
                $objects[] =    eval($this->template('OBJECTS_QUOTE'));
                $varUser   =    " - \\1 {$this->lang->wrote}:";
                $varQuote  =    "\\2";
                $objects[] =    eval($this->template('OBJECTS_QUOTE'));
                $txt = preg_replace($search,$objects,$txt);


voorbeeld( mercuryboard voor diegene die het wil weten):
PHP:
1
2
3
4
5
6
7
8
9
10
$full_search = array(
                    '~\\[(/)?([bius])]~i',
                    '~\[url=(http|https|ftp)://(.+?)](.+?)\[/url]~i',
                    '~\[email]([a-z0-9-_.]+@[a-z0-9-.]+\.[a-z0-9-_.]+)\[/email]~i',
                    '~\\[email=([^<]+?)](.+?)\[/email]~i',
                    '~\[img](http|https|ftp)://(.+?)\[/img]~i',
                    '~\\[(right|center)](.+?)\\[/\1]~is',
                    '~\[code](.+?)\[/code]~is',
                    '~\[php](.+?)\[/php]~ise',
                    '~\\[php=([0-9]+?)](.+?)\
~ise',
'~\[color=(\S+?)](.+?)\[/color]~is',
'~\(.+?)\~is',
'~\\[size=([0-9]+?)](.+?)\[/size]~is'
);

$full_replace = array(
'<\\1\\2>',
'<a href="\\1://\\2" target="' . $this->sets['link_target'] . '">\\3</a>',
'<a href="mailto:\\1">\\1</a>',
'<a href="mailto:\\1">\\2</a>',
'[img]"\\1://\\2"[/img]',
'<div align="\\1">\\2</div>',
'<table align="center" border="0" width="90%" cellpadding="3" cellspacing="0"><tr><td><b>' . $this->lang->main_code . ':</b></td></tr><tr><td class="code">\\1</td></tr></table>',
'$this->colorphp(\'\\1\')',
'$this->colorphp(\'\\2\', \'\\1\')',
'<font color="\\1">\\2</font>',
'<font face="\\1">\\2</font>',
'<font size="\\1">\\2</font>'
);

if((substr_count($in, '
') + substr_count($in, '[quote=')) == substr_count($in, '
')){
$full_search[] = '~\[quote=(.+?)]~i';
$full_search[] = '~\
~i';
$full_search[] = '~\
~i';

$full_replace[] = '<table align="center" border="0" width="90%" cellpadding="3" cellspacing="0"><tr><td><b>\\1 ' . $this->lang->main_said . ':</b></td></tr><tr><td class="quote">';
$full_replace[] = '<table align="center" border="0" width="90%" cellpadding="3" cellspacing="0"><tr><td><b>' . $this->lang->main_quote . ':</b></td></tr><tr><td class="quote">';
$full_replace[] = '</td></tr></table>';
}

$search = array_merge($search, $full_search);
$replace = array_merge($replace, $full_replace);
}
$in = preg_replace($search, $replace, $in);[/php]

Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
niemand?

Acties:
  • 0 Henk 'm!

  • Tomatoman
  • Registratie: November 2000
  • Laatst online: 07:00

Tomatoman

Fulltime prutser

Ik heb hier een stukje code. Dieplood, kun jij dat even voor mij debuggen?
Delphi:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
{$IFDEF USE_ASM}
function Ch256(x, y, z: LongWord): LongWord; assembler;
asm
  and   edx,eax
  not   eax
  and   eax,ecx
  xor   eax,edx
end;
{$ELSE}
function Ch256(x, y, z: LongWord): LongWord;
begin
  Result := (x and y) xor ((not x) and z);
end;
{$ENDIF}

{$IFDEF USE_ASM}
function Maj256(x, y, z: LongWord): LongWord; assembler;
asm
  push  ecx
  and   ecx,eax
  and   eax,edx
  xor   eax,ecx
  pop   ecx
  and   edx,ecx
  xor   eax,edx
end;
{$ELSE}
function Maj256(x, y, z: LongWord): LongWord;
begin
  Result := (x and y) xor (x and z) xor (y and z);
end;
{$ENDIF}

function E0256(x: LongWord): LongWord;
begin
  Result := ror(x, 2) xor ror(x, 13) xor ror(x, 22);
end;

function E1256(x: LongWord): LongWord;
begin
  Result := ror(x, 6) xor ror(x, 11) xor ror(x, 25);
end;

function F0256(x: LongWord): LongWord;
begin
  Result := ror(x, 7) xor ror(x, 18) xor (x shr 3);
end;

function F1256(x: LongWord): LongWord;
begin
  Result := ror(x, 17) xor ror(x, 19) xor (x shr 10);
end;

function ft1(t: Byte; x, y, z: LongWord): LongWord;
begin
  case t of
    0..19: Result := (x and y) or ((not x) and z);
    20..39: Result := x xor y xor z;
    40..59: Result := (x and y) or (x and z) or (y and z);
  else
    Result := x xor y xor z;
  end;
end;

{$IFDEF USE_ASM}
function Kt1(t: Byte): LongWord; assembler;
asm
  cmp   al,19
  jg    @@1
  mov   eax,5a827999h
  jmp   @@end
@@1:
  cmp   al,39
  jg    @@2
  mov   eax,6ed9eba1h
  jmp   @@end
@@2:
  cmp   al,59
  jg    @@3
  mov   eax,8f1bbcdch
  jmp   @@end
@@3:
  mov   eax,0ca62c1d6h
@@end:
end;
{$ELSE}
function Kt1(t: Byte): LongWord;
begin
  case t of
    0..19: Result := $5a827999;
    20..39: Result := $6ed9eba1;
    40..59: Result := $8f1bbcdc;
  else
    Result := $ca62c1d6
  end;
end;
{$ENDIF}

procedure sha1_compress(var md: TSHA256Ctx);
var
  S: array[0..4] of LongWord;
  W: array[0..79] of LongWord;
  i, t: LongWord;
begin
  Move(md.state, S, SizeOf(S));
  for i := 0 to 15 do
    W[i] := Endian(PLongWord(LongWord(@md.buf) + i * 4)^);
  for i := 16 to 79 do
    W[i] := rol(W[i - 3] xor W[i - 8] xor W[i - 14] xor W[i - 16], 1);
    for i := 0 to 79 do
    begin
      t := rol(S[0], 5) + ft1(i, S[1], S[2], S[3]) + S[4] + Kt1(i) + W[i];
      S[4] := S[3];
      S[3] := S[2];
      S[2] := rol(S[1], 30);
      S[1] := S[0];
      S[0] := t;
    end;
  for i := 0 to 4 do
    md.state[i] := md.state[i] + S[i];
end;

procedure sha256_compress(var md: TSHA256Ctx);
var
  S: array[0..7] of LongWord;
  W: array[0..63] of LongWord;
  t1, t2: LongWord;
  i: LongWord;
begin
  Move(md.state, S, SizeOf(S));
  for i := 0 to 15 do
    W[i] := Endian(PLongWord(LongWord(@md.buf) + i * 4)^);
  for i := 16 to 63 do
    W[i] := F1256(W[i - 2]) + W[i - 7] + F0256(W[i - 15]) + W[i - 16];
  for i := 0 to 63 do
  begin
    t1 := S[7] + E1256(S[4]) + Ch256(S[4], S[5], S[6]) + cnstK256[i] + W[i];
    t2 := E0256(S[0]) + Maj256(S[0], S[1], S[2]);
    S[7] := S[6];
    S[6] := S[5];
    S[5] := S[4];
    S[4] := S[3] + t1;
    S[3] := S[2];
    S[2] := S[1];
    S[1] := S[0];
    S[0] := t1 + t2;
  end;
  for i := 0 to 7 do
    md.state[i] := md.state[i] + S[i];
end;

procedure sha512_compress(var md: TSHA512Ctx);
var
  S: array[0..7] of Int64;
  W: array[0..79] of Int64;
  t0, t1: Int64;
  i: LongWord;
begin
  Move(md.state, S, 64);
  for i := 0 to 15 do
    W[i] := Endian64(PInt64(LongWord(@md.buf) + i * 8)^);
  for i := 16 to 79 do
    W[i] := Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W [i - 15]) + W[i - 16];
  for i := 0 to 79 do
  begin
    t0 := S[7] + Sigma1 (S[4]) + Ch (S[4], S[5], S[6]) + cnstK512[i] + W[i];
    t1 := Sigma0 (S[0]) + Maj(S[0], S[1], S[2]);
    S[7] := S[6];
    S[6] := S[5];
    S[5] := S[4];
    S[4] := S[3] + t0;
    S[3] := S[2];
    S[2] := S[1];
    S[1] := S[0];
    S[0] := t0 + t1;
  end;
  for i := 0 to 7 do
    Inc(md.state[i], S[i]);
end;

procedure SHA1Init(var md: TSHA256Ctx);
begin
  md.curlen := 0; md.length := 0;
  md.state[0] := $67452301;
  md.state[1] := $efcdab89;
  md.state[2] := $98badcfe;
  md.state[3] := $10325476;
  md.state[4] := $c3d2e1f0;
end;


Begrijp je de boodschap?

Een goede grap mag vrienden kosten.


Acties:
  • 0 Henk 'm!

Verwijderd

Topicstarter
eigenlijk niet :S .... ik ken geen delphi.. helaas

ik kan het wel ff doorsturen naar iemand die het wel kan, maar dan heb ik wel wat error berichtjes nodig etc. als je begrijpt wat ik bdl...


maar neiamnd weet hoe ik mijn probleem kan oplossen?

Acties:
  • 0 Henk 'm!

  • Tomatoman
  • Registratie: November 2000
  • Laatst online: 07:00

Tomatoman

Fulltime prutser

Wat ik wilde aangeven, is dat je niet zomaar een hoop onbegrijpelijk code moet neerpleuren met het verzoek of iemand jouw probleem effe gaat zitten oplossen. Lees eerst de FAQ maar eens.

Een goede grap mag vrienden kosten.


Acties:
  • 0 Henk 'm!

  • Roa
  • Registratie: December 2002
  • Laatst online: 03-07-2024

Roa

Probeer gewoon es:

PHP:
1
$object[] = $this->formatcode('\\1');
Bovenstaande informatie wordt u gratis aangeboden door tomatoman. Voor nuttige informatie wordt een geringe toeslag in rekening gebracht.
Ik geloof dat dieplood je wat schuldig is tomatoman ;)

Research is what I'm doing when I don't know what I'm doing.


Acties:
  • 0 Henk 'm!

  • crisp
  • Registratie: Februari 2000
  • Nu online

crisp

Devver

Pixelated

ik vermoed dat er ergens een e-modifier ontbreekt....

Intentionally left blank


Acties:
  • 0 Henk 'm!

  • Limhes
  • Registratie: Oktober 2001
  • Laatst online: 08:38
crisp schreef op 01 november 2003 @ 20:02:
ik vermoed dat er ergens een e-modifier ontbreekt....
Lijkt me ook. Je probeert namelijk een callback te doen, maar afaik gaat dit alleen met preg_replace_callback() of idd met de e-modifier. Zie deze code:

PHP:
1
$blaat = preg_replace("/\\$([0-9]+)/e", "(int) \$matcharray[(int) \\1]", $bla);
Pagina: 1