Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute PHP Online

<?php
$txt = "J'apprends à coder"; //chaine initiale (non modifiée)
$r = "CodeR"; //schéma de recherche

//renvoie NULL si pas d'occurences...
$new =  preg_filter("/$r/i", 'programmer' , $txt);
echo $new ."\n";

//renvoie chaine de départ si 0 occurences trouvées
echo preg_replace("/$r/", 'programmer' , $txt) ."\n";

//Recherche schéma au niveau d'un tableau
$r = '/^[^Em]/i'; $r = '/i.$/';
$tab = ['Emeline', 'Emmanuel', 'Charlie', 'Melvil', 'Emric'];

$res = preg_grep($r, $tab);
print_r($res);

//Eclatement cdc en tableau selon schéma de recherche
$r = "/\s/";
$res = preg_split($r, $txt);
print_r($res);

//QUANTIFIEuRS
$r = '/e.?/';
//toutes occurences de e suivies de n'importe quel caractère
preg_match_all($r, $txt, $res); print_r($res);

$r = '/^j/i';
var_dump( preg_match($r, $txt) );

$r = '/s(=?\sà\s)/';
//true si $txt contient s suivi ' à '
var_dump( preg_match($r, $txt) );

$r = '/p{2}/';
//true si $txt contient 2p consécutifs
var_dump( preg_match($r, $txt) );

//on veut un e ou E non suivi d'un m:
$r = '/e(?!m)/i';
print_r( preg_grep($r, $tab) );













Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.