Mailinglisten-Archive |
> -----Original Message-----
> From: php-bounces at phpbar.de [mailto:php-bounces at phpbar.de] On Behalf Of
> Steffen Kother
> Sent: Friday, October 29, 2004 12:01 PM
> To: deutschsprachige PHP-Mailingliste
> Subject: Re: [php] Problem mit preg_match
>
> Hallo Harald,
>
> > $search = '#\[IMG=(.*?)\]#';
> > preg_match ($search, $string, $textArray);
>
> Auf alle Fälle preg_match_all() nehmen. Das reciht ansich schon, da
> stehen alle deine [IMG=xxx] im $textArray[0]...
>
> Bei deinem Such-String evtl. die Klammer auf den ganzen String
> ausweiten, etwa so:
>
> $search = '#(\[IMG=.*?\])#';
>
>
<?php
echo $string = "text [IMG=111] text [IMG=222] text [IMG=333]";
echo $search = '#\[IMG=(.*?)\]#';
preg_match_all ($search, $string, $textArray);
print_r($textArray);
for ($i=0; $i<=count($textArray); $i++) {
echo $textArray[0][$i]."<br>";
}
?>
So kommt das gewünschte ergebniss raus. Wobei ich nicht verstehe warum man
$textArray[0] machen muss.
Lässt man das [0] weg:
Print_r($textarray) liefert:
Array ( [0] => Array ( [0] => [IMG=111] [1] => [IMG=222] [2] => [IMG=333] )
[1] => Array ( [0] => 111 [1] => 222 [2] => 333 ) )
Komisches ding. Warum kommt das?
Gruss seba
php::bar PHP Wiki - Listenarchive