[Php-it] EREG fermarsi alla prima occorrenza

Emiliano Gabrielli (aka AlberT) AlberT at superalbert.it
Wed Jul 12 11:43:07 CEST 2006


On Wednesday 12 July 2006 11:42, Cristiano Verondini wrote:
> >> Devi usare il quantificatore non greedy! :)
> >
> > sicuro ?
>
>     Si, perché altrimenti in questo caso:
>
>         ... {uno} due {tre} ...
>
>     prenderesti 'uno} due {tre'
>
>         Cris

albert at gabrielli: .../tmp/ $ cat prova.php
<?php
$a = "sono un testo ... {parola1} con certe parole {frase 1} o frasi .... {le 
prendi tutte?}..";
preg_match_all('#\{([^}]+)\}#', $a, $matches);

var_dump($matches);
?>
albert at gabrielli: .../tmp/ $ php4 prova.php

array(2) {
  [0]=>
  array(3) {
    [0]=>
    string(9) "{parola1}"
    [1]=>
    string(9) "{frase 1}"
    [2]=>
    string(18) "{le prendi tutte?}"
  }
  [1]=>
  array(3) {
    [0]=>
    string(7) "parola1"
    [1]=>
    string(7) "frase 1"
    [2]=>
    string(16) "le prendi tutte?"
  }
}


-- 
<?php echo '     Emiliano Gabrielli (aka AlberT)     ',"\n",
'  socio fondatore e membro del direttivo del GrUSP  ',"\n",
' AlberT_at_SuperAlberT_it   -   www.SuperAlberT.it  ',"\n",
'  IRC:    #php,#AES azzurra.com ',"\n",'ICQ: 158591185'; ?>


More information about the Php-it mailing list