Archivlink: javarea.de Forum > PHP, MySQL & CGI > preg_replace --> confused
Vollständigen Link anzeigen: javarea.de Forum > PHP, MySQL & CGI > preg_replace --> confused

Pages: [1]

geschrieben von Klaush am 28.02.2008 - 10:59

geschrieben von okley am 28.02.2008 - 16:46
Ich würde sagen da stimmt was mit dem Regex nicht. Weil er nimmt dir ja anscheinend nur die zweite Attachmentnummer aus dem Input 0>546. Auf die Idee komm ich wegen der attachmentid 550 beim zweiten Link. Weil die wird ja im Input nicht mitgegeben.

EDIT:
Zudem matched dein Regex .* ja auch den zweiten [attach] Tag.
Probier mal den Regex:
\[attach\](\d\d\d)\[\/attach\]/esiU

geschrieben von Klaush am 28.02.2008 - 19:35
Check ich morgen ab, habe heute wenig Zeit.

Danke erst einmal!

geschrieben von Klaush am 29.02.2008 - 09:32
Kein Erfolg!

ich habe mal eine Testumgebung gebaut:
PHP-Quelltext
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: 

<?
// debug-function
function infoArray($String
{
    print 
'<pre>'
    
print_r($String); 
    print 
'</pre>';
}

// Attachment-Array
$cache 
Array
(    
    
963 => Array
            (
                
550 => Array
                        (
                            
=> 550,
                            
=> 963,
                            
=> 'test.rar',
                            
=> 1622,
                            
=> '',
                            
=> 1,
                            
=> 'application/octet-st',
                            
=> 550
                        
),                    
                
548 => Array
                        (
                            
=> 548,
                            
=> 963,
                            
=> 'Green Sea Turtle.jpg',
                            
=> 378729,
                            
=> '1024/768',
                            
=> 0
                            
=> 'image/jpeg'
                        
),
                
545 => Array
                        (
                            
=> 545,
                            
=> 963,
                            
=> 'Garden.jpg',
                            
=> 516424,
                            
=> '1024/768',
                            
=> 1,
                            
6=> 'image/jpeg',
                            
=> 545
                        
)
            )
);

$string "  ";

if (
count($cache))
{    
    foreach(
$cache As $key1 => $arrPostID
    {                
        foreach(
$arrPostID As $key2 => $arrAttachID
        {                
            if (!empty(
$arrAttachID[7]) AND !empty($arrAttachID[4]))
            {    
                
$search[] = "/\[attach\](\d\d\d)\[\/attach\]/esiU"
                
$replace[] = "'<img src=attachment.php3?thumbnailid=$1 border=1>'";        
            }elseif (!empty(
$arrAttachID[7]) AND empty($arrAttachID[4]))
            {
                
$search[] = "/\[attach\](\d\d\d)\[\/attach\]/esiU"
                
$replace[] = "'<a href=attachment.php3?attachmentid=$1>$arrAttachID[2]</a>'";                                
            }
        }
    }
}

if (
is_array($search) AND is_array($replace) AND !empty($string))
{
    
ksort($search);
    
ksort($replace);    
    
    
// debug-function
    
infoArray($search);
    
infoArray($replace);
    
    echo 
preg_replace($search$replace$string);
}
?>



Die Ausgabe sieht dann wie auf dem Bild aus. Es kann also nicht am regex liegen, ich tippe mal auf die Funktion selsbt die in diesem Beispiel nicht geeignet ist!??.


Powered by: JBB v.2.0.4 Copyright ©2000-2006, www.javarea.de.