user2720263
user2720263

Reputation: 11

Deprecated: Function ereg() & ereg_replace()

i'm actually using a script i've used for years before and when i put it in my website, i got the error "Deprecated: Function ereg() & ereg_replace()". I'm actually unable to understand how to modify the ereg() things in preg() things. If someone is able to able, i'll appreciate!

Here is my code:

   // couleur
   $t=str_replace("[/color]", "</span>", $t);
   $regCouleur="\[color= ?(([[:alpha:]]+)|(#[[:digit:][:alpha:]]{6})) ?\]";
   $t=ereg_replace($regCouleur, "<span style=\"color: \\1\">", $t);

   // taille des caractères
   $t=str_replace("[/size]", "</span>", $t);
   $regCouleur="\[size= ?([[:digit:]]+) ?\]";
   $t=ereg_replace($regCouleur, "<span style=\"font-size: \\1px\">", $t);

   // lien
   $regLienSimple="\[url\] ?([^\[]*) ?\[/url\]";
   $regLienEtendu="\[url ?=([^\[]*) ?] ?([^]]*) ?\[/url\]";
   if (ereg($regLienSimple, $t)) $t=ereg_replace($regLienSimple, "<a href=\"\\1\">\\1</a>", $t);
   else $t=ereg_replace($regLienEtendu, "<a href=\"\\1\" target=\"_blank\">\\2</a>", $t);

   // mail
   $regMailSimple="\[email\] ?([^\[]*) ?\[/email\]";
   $regMailEtendu="\[email ?=([^\[]*) ?] ?([^]]*) ?\[/email\]";
   if (ereg($regMailSimple, $t)) $t=ereg_replace($regMailSimple, "<a href=\"mailto:\\1\">\\1</a>", $t);
   else $t=ereg_replace($regMailEtendu, "<a href=\"mailto:\\1\">\\2</a>", $t);

   // image
   $regImage="\[img\] ?([^\[]*) ?\[/img\]";
   $regImageAlternatif="\[img ?= ?([^\[]*) ?\]";
   if (ereg($regImage, $t)) $t=ereg_replace($regImage, "<img src=\"\\1\" alt=\"\" border=\"0\" />", $t);
   else $t=ereg_replace($regImageAlternatif, "<img src=\"\\1\" alt=\"\" border=\"0\" />", $t);

   // Video

   $regVidSimple="\[video\] ?([^\[]*) ?\[/video\]";
   $regVidEtendu="\[video ?=([^\[]*) ?] ?([^]]*) ?\[/video\]";
   if (ereg($regVidSimple, $t)) $t=ereg_replace($regVidSimple, "<p style=\"text-align: center;\"><object style=\"background-color: rgb(255, 255, 204); background-position: 50% 50%;\" data=\"\\1\" type=\"application/x-shockwave-flash\" height=\"190\" width=\"240\"><param name=\"src\" value=\"\\1\"></object></p>", $t);
   else $t=ereg_replace($regVidEtendu, "<iframe title=\"YouTube video player\" width=\"240\" height=\"190\" src=\"\\1\" frameborder=\"0\" allowfullscreen>\\2</iframe>", $t);

Thanks for your answers !

Upvotes: 0

Views: 201

Answers (1)

SL5net
SL5net

Reputation: 2566

Try this:

$regCouleur="/\[color=\s+(([[:alpha:]]+)|(#[[:digit:][:alpha:]]{6}))\s+\]/";
$t=preg_replace($regCouleur, "<span style=\"font-size: \\1px\">', $t);

By the way, could you please add a source and an expected string?

Upvotes: 0

Related Questions