par
correlatif » 07 sept. 2018, 22:48
Utilises print() quand tu debug un array
En reprenant ton premier exemple
$re = '/E-mail : (.*) Site Web/m';
$str = 'E-mail : [email protected] Site Web : www.tot.c Forme : Rond';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
var_dump($matches[0][1]);
Résultat => string(10) "
[email protected]"
Tu pouvais aussi obtenir le même résultat avec preg_replace
$re = '/(.*):(.*)Site(.*)/sm';
$str = 'E-mail : [email protected] Site Web : www.tot.c Forme : Rond';
$result = trim(preg_replace($re, '\2', $str));
var_dump( $result );
Résultat => string(10) "
[email protected]"
Utilises print() quand tu debug un array
En reprenant ton premier exemple
[PHP]
$re = '/E-mail : (.*) Site Web/m';
$str = 'E-mail :
[email protected] Site Web : www.tot.c Forme : Rond';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
var_dump($matches[0][1]);
[/PHP]
Résultat => string(10) "
[email protected]"
Tu pouvais aussi obtenir le même résultat avec preg_replace
[PHP]$re = '/(.*):(.*)Site(.*)/sm';
$str = 'E-mail :
[email protected] Site Web : www.tot.c Forme : Rond';
$result = trim(preg_replace($re, '\2', $str));
var_dump( $result );[/PHP]
Résultat => string(10) "
[email protected]"