par
Naroth » 11 août 2016, 18:33
Bonjour,
Je ne suis pas expert en regex mais ":blanck:" ne me dit absolument rien pour les regexs, en tout cas ce n'est pas reconnu par PHP
Warning: preg_match_all(): Compilation failed: unknown POSIX class name at offset 5 in C:\wamp\www\test.php on line 5
Je te propose donc la solution suivante
$matchs = array();
$string = "2^315 = 4<br>3^215 = 9<br>4^22 = 16<br>5^2456a4 = 25";
preg_match_all("/\^\[0-9]+/",$string,$matchs);
foreach($matchs[0] as $match)
{
$currentMatch = substr($match, 1); //suppression du ^
$string = str_replace($match,"<sup>$currentMatch</sup>", $string);
}
echo $string;
Output :
Elle est encore améliorable notamment car ma regex ne recherche que les nombres.
Bonjour,
Je ne suis pas expert en regex mais ":blanck:" ne me dit absolument rien pour les regexs, en tout cas ce n'est pas reconnu par PHP
[html]Warning: preg_match_all(): Compilation failed: unknown POSIX class name at offset 5 in C:\wamp\www\test.php on line 5[/html]
Je te propose donc la solution suivante
[php]$matchs = array();
$string = "2^315 = 4<br>3^215 = 9<br>4^22 = 16<br>5^2456a4 = 25";
preg_match_all("/\^\[0-9]+/",$string,$matchs);
foreach($matchs[0] as $match)
{
$currentMatch = substr($match, 1); //suppression du ^
$string = str_replace($match,"<sup>$currentMatch</sup>", $string);
}
echo $string;[/php]
Output :
[img]http://img4.hostingpics.net/pics/205339Capture.jpg[/img]
Elle est encore améliorable notamment car ma regex ne recherche que les nombres.