par
azzeryx » 06 sept. 2016, 17:54
Je peut effectivement donner les fonctions complètes (très longue) :
Code : Tout sélectionner
<?php
function texte($var, $type='', $non='', $id='')
{
if(preg_match_all("/\+@[^\s[:punct:]]+/",$var,$match))
{
foreach ($match as $v1) {
foreach ($v1 as $c=>$v2) {
$pseudo = str_replace("+@", "", $v2);
$replacement = "<a target='_blank' href='site.php?section=autre_profile&personne=$pseudo'>".$v2."</a>";
$var = str_replace($v2, $replacement, $var);
}
}
}
$var = preg_replace('/\\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i', "<a target='_blank' href='$0'>$0</a>", $var);
$var = str_replace("\n", "<br/>", $var);
$var = str_replace("<a href="", "<a target='_blank' href='", $var);
$var = str_replace("">", "'>", $var);
$var = str_replace("</a>", "</a>", $var);
if($type=='')
{
$var = str_replace("<titre>", "<h2 style='color: rgb(0,128,255); font-size: 25px; text-align: center;' >", $var);
$var = str_replace("</titre>", "</h2>", $var);
$var = str_replace("<sous-titre>", "<h3 style='color: rgb(0,128,255); font-size: 20px; text-align: center;' >", $var);
$var = str_replace("</sous-titre>", "</h3>", $var);
$var = str_replace("<attention>", "<img src='images/attention.jpg' alt='attention' height='20px' width='20px'/> <span style='background-color: rgb(255, 201, 14);' >", $var);
$var = str_replace("</attention>", "</span>", $var);
$var = str_replace("<liste>", "<ul>", $var);
$var = str_replace("<liste_num>", "<ol>", $var);
$var = str_replace("<puce>", "<li>", $var);
$var = str_replace("</puce>", "</li>", $var);
$var = str_replace("</liste>", "</ol>", $var);
$var = str_replace("</liste>", "</ul>", $var);
$var = str_replace("<tableau>", "<table>", $var);
$var = str_replace("<tête>", "<thead>", $var);
$var = str_replace("<corps>", "<tbody>", $var);
$var = str_replace("<ligne>", "<tr>", $var);
$var = str_replace("<cellule-tête>", "<th>", $var);
$var = str_replace("</cellule-tête>", "</th>", $var);
$var = str_replace("<cellule>", "<td>", $var);
$var = str_replace("</cellule>", "</td>", $var);
$var = str_replace("</ligne>", "</tr>", $var);
$var = str_replace("</corps>", "</tbody>", $var);
$var = str_replace("</tête>", "</thead>", $var);
$var = str_replace("</tableau>", "</table>", $var);
if(preg_match_all("/{\[def:(.*)\]\[id=(.*)\]\[(.*)\]}/", $var, $matches))
{
$var = preg_replace("/{\[def:(.*)\]\[id=(.*)\]\[(.*)\]}/", "<dl style=\"width:80%; border:1px solid gray; padding:1px; font-family:swiss; border-top:3px solid rgb(63,72,204); background-color: rgba(148,182,239,0.75);\"><dt style=\"font-weight:bold;\">$1 :</dt><dd>$3</dd></dl>", $var);
}
}
$var = preg_replace("/::<(.*)/>::/", "<strong style='font-weight: bold;' >$0</strong>", $var);
//on gère les couleurs en hexa
if(preg_match_all("/<couleur\[#[a-fA-F0-9]{6}\]>/",$var,$match))
{
foreach ($match as $v1) {
foreach ($v1 as $c=>$v2) {
preg_match_all("/#[a-fA-F0-9]{6}/", $v2, $match2);
$match2 = $match2[0][0];
$replacement = "<span style='color:$match2;'>";
$var = str_replace($v2, $replacement, $var);
}
}
}
$var = str_replace("</couleur>", "</span>", $var);
//balise math
if(preg_match_all("/\[\[:math:\[\[(.*)\]\]:math:\]\]/U",$var,$match))
{
foreach ($match as $v1) {
foreach ($v1 as $c=>$v2) {
$r = "<br/><br/><span style='color:gray; font-size:12px;'>math :</span> ";
$r .= "<a HREF='javascript: codeSelect(\"math".$c.'_'.$id."\");' style='color: blue; font-size:12px;'>Selectionner tout le texte</a><br/>";
$r = $r."<div class='math' id='math".$c.'_'.$id."' style='background-color:rgb(230,230,230); border:1px solid gray; max-width: 80%; font-size: 13px;'><ol><li style='float:left;'></li>";
$r2 = "</ol></div>";
$var = str_replace("[[:math:[[", $r, $var);
$var = str_replace("]]:math:]]", $r2, $var);
//$non compris dans la balise math
if($non!='' && strstr($v2, $non))
{
$non3=str_replace("\"", "'", $non);
$non2="</ol>".$non3."<ol id=\"ol2\"><li style=\"float:left;\" ></li>";
//$var = str_replace($non, $non2, $var);
//séparer en 2
$part[0] = strstr($v2, $non);
$part[0] = str_replace($non, '', $part[0]);
$part[1] = strstr($v2, $non, true); // Depuis PHP 5.3.0
$nombre_ligne_ol=substr_count($part[1], "<br/>")+2;
$non2 = str_replace("<ol id=\"ol2\">", "<ol start=".$nombre_ligne_ol.">", $non2);
$var = str_replace($non, $non2, $var);
foreach ($part as $key => $value) {
$math = math($part[$key]);
$math = str_replace("<br/>", "<br/><li style='float:left;'></li>", $math);
$var = str_replace($part[$key], $math, $var);
}
}
else
{
$math = math($v2);
$math = str_replace("<br/>", "<br/><li style='float:left;'></li>", $math);
$var = str_replace($v2, $math, $var);
}
}
}
}
$var = str_replace("""<", "<img src='images/guillemets.jpg' alt='guillemets' height='20px' width='20px'/> <span style='font-style: italic;' >", $var);
$var = str_replace("/>""", "</span>", $var);
$var = str_replace(":D", "<img src='../smiley/17473777-happy-smiley-emoticon.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace(":'(", "<img src='../smiley/33886503-smiley-triste-dessin-anim--motic-ne.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace("<diable/>", "<img src='../smiley/7513465-diable-motic-ne.jpg' alt='smiley' height='20px' width='30px'/>", $var);
$var = str_replace("<réfléchit/>", "<img src='../smiley/16515888-emoticon-smiley-pens-e.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace("<dsl/>", "<img src='../smiley/9718593-d-sol--motic-ne.jpg' alt='smiley' height='30px' width='30px'/>", $var);
$var = str_replace("<clap/>", "<img src='../smiley/13172924-applaudissements-emoticon.jpg' alt='smiley' height='30px' width='30px'/>", $var);
$var = str_replace("$)", "<img src='../smiley/7327892-dollar-motic-ne.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace(":)", "<img src='../smiley/8711244-motic-ne.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace(":(", "<img src='../smiley/pas_contant.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace(";)", "<img src='../smiley/19287364-soup-onnant-motic-ne.jpg' alt='smiley pas contant' height='20px' width='20px'/>", $var);
$var = str_replace("<3)", "<img src='../smiley/8598200-en-amour-motic-ne.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace("<3", "<img src='../smiley/coeur.jpg' alt='coeur' height='20px' width='20px'/>", $var);
return $var;
}
function math($math)
{
if(preg_match_all("/\^\S+/",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$sup = str_replace('^', '', $v2_math);
$replacement_math = "<SUP>".$sup."</SUP>";
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
if(preg_match_all("/_\S+/",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$sup = str_replace('_', '', $v2_math);
$replacement_math = "<SUB>".$sup."</SUB>";
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
//$math = str_replace("/", "<font color='blue'>\/</font>", $math);
$math = str_replace("=", "<font color='red'>=</font>", $math);
$math = str_replace("~=", "<font color='red'>≈</font>", $math);
$math = str_replace("<", "<font color='red'><</font>", $math);
$math = str_replace(">", "<font color='red'>></font>", $math);
$math = str_replace("≤", "<font color='red'>≤</font>", $math);
$math = str_replace("≥", "<font color='red'>≥</font>", $math);
$math = str_replace("+", "<font color='blue'>+</font>", $math);
$math = str_replace("-", "<font color='blue'>-</font>", $math);
$math = str_replace("*", "<font color='blue'>×</font>", $math);
$math = str_replace("×", "<font color='blue'>×</font>", $math);
$math = str_replace("[div]", "<font color='blue'>÷</font>", $math);
$math = str_replace("÷", "<font color='blue'>÷</font>", $math);
$math = str_replace("π", "<font color='orange'>π</font>", $math);
$math = str_replace("PI", "<font color='orange'>π</font>", $math);
$pattern = "/(?<![\\\\])(inf\.)/"; // pas précéder de \ (?<![\\\\])
$math = preg_replace($pattern, "<font color='orange'>∞</font>", $math);
$math = str_replace("%", "<font color='purple'>%</font>", $math);
$math = str_replace("inclu()","⊂", $math);
$math = str_replace("ninclu()","⊄", $math);
$math = str_replace("E()","∈", $math);
$math = str_replace("!∈","∉", $math);
$math = str_replace("|N","ℕ", $math);
$math = str_replace("|Z","ℤ", $math);
$math = str_replace("|Q","ℚ", $math);
$math = str_replace("|R","ℝ", $math);
$math = str_replace("|C","ℂ", $math);
$math = str_replace("integ()","∫", $math);
$math = str_replace("som()","<font color='maroon'>∑</font>", $math);
$math = str_replace("∑","<font color='maroon'>∑</font>", $math);
$math = str_replace("prod()","<font color='maroon'>∏</font>", $math);
$math = str_replace("∏","<font color='maroon'>∏</font>", $math);
$math = str_replace("perp()","⊥", $math);
$math = str_replace("O/","∅", $math);
if(preg_match_all("/[0-9]*\.?[0-9]+/",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$replacement_math = "<font color='green'>".$v2_math."</font>";
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
$pattern = "/(?<![\\\\])([!eE])\./"; // pas précéder de \ (?<![\\\\])
$math = preg_replace($pattern, '<font color=\'purple\'>$1</font>', $math);
if(preg_match_all("/\\\\(!|e|E|inf)\./",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$replacement_math = str_replace("\\", "", $v2_math);
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
if(preg_match_all("/(log|ln)\((.*)\)/",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$replacement_math = "<font color='purple'>".$v2_math."</font>";
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
return $math;
}
//fonction utile
function str_replace_occurence ($search, $replace, $subject, $occurence) {
$occurence = array_flip((array)$occurence);
$search = array_values((array)$search);
$replace = array_values((array)$replace);
if (empty($subject) || empty($search))
return $subject;
if (($scount = count($search)) != count($replace))
return false;
foreach ($search as $offset => $needle) {
$pos = 0;
$len = strlen($needle);
$rep = $replace[$offset];
$occur = 0;
while (($pos = strpos($subject, $needle, $pos)) !== false && ++$occur) {
if (isset($occurence[$occur]))
($subject = substr($subject, 0, $pos) . $rep . substr($subject, $pos + $len));
$pos += $len;
}
}
return $subject;
}
//fonction pour couper le texte
function tronquer($origine, $longueurAGarder, $id)
{
$origine = str_replace("\n", "<br/>", $origine);
$nombre_ligne_fichier=substr_count($origine, "<br/>");
$nombre_ligne_fichier=$nombre_ligne_fichier+1;
if (strlen ($origine) <= $longueurAGarder && $nombre_ligne_fichier <= 5)
{
return array($origine, '');
}
else
{
if(strlen ($origine) >= $longueurAGarder && $nombre_ligne_fichier <= 6)
{
//$string = "<span id='cacher".$id."' style='display: none;'>";
$string = "<span id=\"cacher".$id."\" style=\"display: none;\">";
//étape 1
$nombre_ligne_fichier=substr_count($origine, "<br/>");
$nombre_ligne_fichier=$nombre_ligne_fichier+1;
$debut = substr($origine, 0, $longueurAGarder);
$lire = $debut . $string;
$finale = str_replace($debut, $lire, $origine);
//étape 2
$fin = $finale . "</span> <a HREF='javascript: Apparait(".$id.");' id='plus".$id."' style='bcolor blue; text-decoration: none; font-size: 12px;' > lire la suite (".$nombre_ligne_fichier." l.)</a> <a HREF='javascript: Disparait(".$id.");' id='moins".$id."' style='bcolor blue; text-decoration: none; font-size: 12px; display: none;' >Moins (".$nombre_ligne_fichier." l.)</a>";
$finale = str_replace($finale, $fin, $finale);
return array($finale, $string);
//return $origine;
}
else if ($nombre_ligne_fichier > 6)
{
//étape 1
//$string = "<span id='cacher".$id."' style='display: none;'>";
$string = "<span id=\"cacher".$id."\" style=\"display: none;\">";
$origine = str_replace_occurence('<br/>', $string, $origine, 5);
//étape 2
$fin = $origine . "</span> <a HREF='javascript: Apparait(".$id.");' id='plus".$id."' style='bcolor blue; text-decoration: none; font-size: 12px;' > lire la suite (".$nombre_ligne_fichier." l.)</a> <a HREF='javascript: Disparait(".$id.");' id='moins".$id."' style='bcolor blue; text-decoration: none; font-size: 12px; display: none;' >Moins (".$nombre_ligne_fichier." l.)</a>";
$finale = str_replace($origine, $fin, $origine);
return array($finale, $string);
}
}
}
?>
C'est simple toutes les partie de ces fonction qui utilisent des array (y compris des return) ne fonctionnent pas quand j'appel la page en ajax. En revanche quand j'appelle la page normalement ça marche.
Je peut effectivement donner les fonctions complètes (très longue) :
[code]
<?php
function texte($var, $type='', $non='', $id='')
{
if(preg_match_all("/\+@[^\s[:punct:]]+/",$var,$match))
{
foreach ($match as $v1) {
foreach ($v1 as $c=>$v2) {
$pseudo = str_replace("+@", "", $v2);
$replacement = "<a target='_blank' href='site.php?section=autre_profile&personne=$pseudo'>".$v2."</a>";
$var = str_replace($v2, $replacement, $var);
}
}
}
$var = preg_replace('/\\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|]/i', "<a target='_blank' href='$0'>$0</a>", $var);
$var = str_replace("\n", "<br/>", $var);
$var = str_replace("<a href="", "<a target='_blank' href='", $var);
$var = str_replace("">", "'>", $var);
$var = str_replace("</a>", "</a>", $var);
if($type=='')
{
$var = str_replace("<titre>", "<h2 style='color: rgb(0,128,255); font-size: 25px; text-align: center;' >", $var);
$var = str_replace("</titre>", "</h2>", $var);
$var = str_replace("<sous-titre>", "<h3 style='color: rgb(0,128,255); font-size: 20px; text-align: center;' >", $var);
$var = str_replace("</sous-titre>", "</h3>", $var);
$var = str_replace("<attention>", "<img src='images/attention.jpg' alt='attention' height='20px' width='20px'/> <span style='background-color: rgb(255, 201, 14);' >", $var);
$var = str_replace("</attention>", "</span>", $var);
$var = str_replace("<liste>", "<ul>", $var);
$var = str_replace("<liste_num>", "<ol>", $var);
$var = str_replace("<puce>", "<li>", $var);
$var = str_replace("</puce>", "</li>", $var);
$var = str_replace("</liste>", "</ol>", $var);
$var = str_replace("</liste>", "</ul>", $var);
$var = str_replace("<tableau>", "<table>", $var);
$var = str_replace("<tête>", "<thead>", $var);
$var = str_replace("<corps>", "<tbody>", $var);
$var = str_replace("<ligne>", "<tr>", $var);
$var = str_replace("<cellule-tête>", "<th>", $var);
$var = str_replace("</cellule-tête>", "</th>", $var);
$var = str_replace("<cellule>", "<td>", $var);
$var = str_replace("</cellule>", "</td>", $var);
$var = str_replace("</ligne>", "</tr>", $var);
$var = str_replace("</corps>", "</tbody>", $var);
$var = str_replace("</tête>", "</thead>", $var);
$var = str_replace("</tableau>", "</table>", $var);
if(preg_match_all("/{\[def:(.*)\]\[id=(.*)\]\[(.*)\]}/", $var, $matches))
{
$var = preg_replace("/{\[def:(.*)\]\[id=(.*)\]\[(.*)\]}/", "<dl style=\"width:80%; border:1px solid gray; padding:1px; font-family:swiss; border-top:3px solid rgb(63,72,204); background-color: rgba(148,182,239,0.75);\"><dt style=\"font-weight:bold;\">$1 :</dt><dd>$3</dd></dl>", $var);
}
}
$var = preg_replace("/::<(.*)/>::/", "<strong style='font-weight: bold;' >$0</strong>", $var);
//on gère les couleurs en hexa
if(preg_match_all("/<couleur\[#[a-fA-F0-9]{6}\]>/",$var,$match))
{
foreach ($match as $v1) {
foreach ($v1 as $c=>$v2) {
preg_match_all("/#[a-fA-F0-9]{6}/", $v2, $match2);
$match2 = $match2[0][0];
$replacement = "<span style='color:$match2;'>";
$var = str_replace($v2, $replacement, $var);
}
}
}
$var = str_replace("</couleur>", "</span>", $var);
//balise math
if(preg_match_all("/\[\[:math:\[\[(.*)\]\]:math:\]\]/U",$var,$match))
{
foreach ($match as $v1) {
foreach ($v1 as $c=>$v2) {
$r = "<br/><br/><span style='color:gray; font-size:12px;'>math :</span> ";
$r .= "<a HREF='javascript: codeSelect(\"math".$c.'_'.$id."\");' style='color: blue; font-size:12px;'>Selectionner tout le texte</a><br/>";
$r = $r."<div class='math' id='math".$c.'_'.$id."' style='background-color:rgb(230,230,230); border:1px solid gray; max-width: 80%; font-size: 13px;'><ol><li style='float:left;'></li>";
$r2 = "</ol></div>";
$var = str_replace("[[:math:[[", $r, $var);
$var = str_replace("]]:math:]]", $r2, $var);
//$non compris dans la balise math
if($non!='' && strstr($v2, $non))
{
$non3=str_replace("\"", "'", $non);
$non2="</ol>".$non3."<ol id=\"ol2\"><li style=\"float:left;\" ></li>";
//$var = str_replace($non, $non2, $var);
//séparer en 2
$part[0] = strstr($v2, $non);
$part[0] = str_replace($non, '', $part[0]);
$part[1] = strstr($v2, $non, true); // Depuis PHP 5.3.0
$nombre_ligne_ol=substr_count($part[1], "<br/>")+2;
$non2 = str_replace("<ol id=\"ol2\">", "<ol start=".$nombre_ligne_ol.">", $non2);
$var = str_replace($non, $non2, $var);
foreach ($part as $key => $value) {
$math = math($part[$key]);
$math = str_replace("<br/>", "<br/><li style='float:left;'></li>", $math);
$var = str_replace($part[$key], $math, $var);
}
}
else
{
$math = math($v2);
$math = str_replace("<br/>", "<br/><li style='float:left;'></li>", $math);
$var = str_replace($v2, $math, $var);
}
}
}
}
$var = str_replace("""<", "<img src='images/guillemets.jpg' alt='guillemets' height='20px' width='20px'/> <span style='font-style: italic;' >", $var);
$var = str_replace("/>""", "</span>", $var);
$var = str_replace(":D", "<img src='../smiley/17473777-happy-smiley-emoticon.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace(":'(", "<img src='../smiley/33886503-smiley-triste-dessin-anim--motic-ne.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace("<diable/>", "<img src='../smiley/7513465-diable-motic-ne.jpg' alt='smiley' height='20px' width='30px'/>", $var);
$var = str_replace("<réfléchit/>", "<img src='../smiley/16515888-emoticon-smiley-pens-e.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace("<dsl/>", "<img src='../smiley/9718593-d-sol--motic-ne.jpg' alt='smiley' height='30px' width='30px'/>", $var);
$var = str_replace("<clap/>", "<img src='../smiley/13172924-applaudissements-emoticon.jpg' alt='smiley' height='30px' width='30px'/>", $var);
$var = str_replace("$)", "<img src='../smiley/7327892-dollar-motic-ne.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace(":)", "<img src='../smiley/8711244-motic-ne.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace(":(", "<img src='../smiley/pas_contant.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace(";)", "<img src='../smiley/19287364-soup-onnant-motic-ne.jpg' alt='smiley pas contant' height='20px' width='20px'/>", $var);
$var = str_replace("<3)", "<img src='../smiley/8598200-en-amour-motic-ne.jpg' alt='smiley' height='20px' width='20px'/>", $var);
$var = str_replace("<3", "<img src='../smiley/coeur.jpg' alt='coeur' height='20px' width='20px'/>", $var);
return $var;
}
function math($math)
{
if(preg_match_all("/\^\S+/",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$sup = str_replace('^', '', $v2_math);
$replacement_math = "<SUP>".$sup."</SUP>";
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
if(preg_match_all("/_\S+/",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$sup = str_replace('_', '', $v2_math);
$replacement_math = "<SUB>".$sup."</SUB>";
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
//$math = str_replace("/", "<font color='blue'>\/</font>", $math);
$math = str_replace("=", "<font color='red'>=</font>", $math);
$math = str_replace("~=", "<font color='red'>≈</font>", $math);
$math = str_replace("<", "<font color='red'><</font>", $math);
$math = str_replace(">", "<font color='red'>></font>", $math);
$math = str_replace("≤", "<font color='red'>≤</font>", $math);
$math = str_replace("≥", "<font color='red'>≥</font>", $math);
$math = str_replace("+", "<font color='blue'>+</font>", $math);
$math = str_replace("-", "<font color='blue'>-</font>", $math);
$math = str_replace("*", "<font color='blue'>×</font>", $math);
$math = str_replace("×", "<font color='blue'>×</font>", $math);
$math = str_replace("[div]", "<font color='blue'>÷</font>", $math);
$math = str_replace("÷", "<font color='blue'>÷</font>", $math);
$math = str_replace("π", "<font color='orange'>π</font>", $math);
$math = str_replace("PI", "<font color='orange'>π</font>", $math);
$pattern = "/(?<![\\\\])(inf\.)/"; // pas précéder de \ (?<![\\\\])
$math = preg_replace($pattern, "<font color='orange'>∞</font>", $math);
$math = str_replace("%", "<font color='purple'>%</font>", $math);
$math = str_replace("inclu()","⊂", $math);
$math = str_replace("ninclu()","⊄", $math);
$math = str_replace("E()","∈", $math);
$math = str_replace("!∈","∉", $math);
$math = str_replace("|N","ℕ", $math);
$math = str_replace("|Z","ℤ", $math);
$math = str_replace("|Q","ℚ", $math);
$math = str_replace("|R","ℝ", $math);
$math = str_replace("|C","ℂ", $math);
$math = str_replace("integ()","∫", $math);
$math = str_replace("som()","<font color='maroon'>∑</font>", $math);
$math = str_replace("∑","<font color='maroon'>∑</font>", $math);
$math = str_replace("prod()","<font color='maroon'>∏</font>", $math);
$math = str_replace("∏","<font color='maroon'>∏</font>", $math);
$math = str_replace("perp()","⊥", $math);
$math = str_replace("O/","∅", $math);
if(preg_match_all("/[0-9]*\.?[0-9]+/",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$replacement_math = "<font color='green'>".$v2_math."</font>";
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
$pattern = "/(?<![\\\\])([!eE])\./"; // pas précéder de \ (?<![\\\\])
$math = preg_replace($pattern, '<font color=\'purple\'>$1</font>', $math);
if(preg_match_all("/\\\\(!|e|E|inf)\./",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$replacement_math = str_replace("\\", "", $v2_math);
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
if(preg_match_all("/(log|ln)\((.*)\)/",$math,$match_math))
{
foreach ($match_math as $v1_math) {
foreach ($v1_math as $c_math=>$v2_math) {
$replacement_math = "<font color='purple'>".$v2_math."</font>";
$math = str_replace($v2_math, $replacement_math, $math);
}
}
}
return $math;
}
//fonction utile
function str_replace_occurence ($search, $replace, $subject, $occurence) {
$occurence = array_flip((array)$occurence);
$search = array_values((array)$search);
$replace = array_values((array)$replace);
if (empty($subject) || empty($search))
return $subject;
if (($scount = count($search)) != count($replace))
return false;
foreach ($search as $offset => $needle) {
$pos = 0;
$len = strlen($needle);
$rep = $replace[$offset];
$occur = 0;
while (($pos = strpos($subject, $needle, $pos)) !== false && ++$occur) {
if (isset($occurence[$occur]))
($subject = substr($subject, 0, $pos) . $rep . substr($subject, $pos + $len));
$pos += $len;
}
}
return $subject;
}
//fonction pour couper le texte
function tronquer($origine, $longueurAGarder, $id)
{
$origine = str_replace("\n", "<br/>", $origine);
$nombre_ligne_fichier=substr_count($origine, "<br/>");
$nombre_ligne_fichier=$nombre_ligne_fichier+1;
if (strlen ($origine) <= $longueurAGarder && $nombre_ligne_fichier <= 5)
{
return array($origine, '');
}
else
{
if(strlen ($origine) >= $longueurAGarder && $nombre_ligne_fichier <= 6)
{
//$string = "<span id='cacher".$id."' style='display: none;'>";
$string = "<span id=\"cacher".$id."\" style=\"display: none;\">";
//étape 1
$nombre_ligne_fichier=substr_count($origine, "<br/>");
$nombre_ligne_fichier=$nombre_ligne_fichier+1;
$debut = substr($origine, 0, $longueurAGarder);
$lire = $debut . $string;
$finale = str_replace($debut, $lire, $origine);
//étape 2
$fin = $finale . "</span> <a HREF='javascript: Apparait(".$id.");' id='plus".$id."' style='bcolor blue; text-decoration: none; font-size: 12px;' > lire la suite (".$nombre_ligne_fichier." l.)</a> <a HREF='javascript: Disparait(".$id.");' id='moins".$id."' style='bcolor blue; text-decoration: none; font-size: 12px; display: none;' >Moins (".$nombre_ligne_fichier." l.)</a>";
$finale = str_replace($finale, $fin, $finale);
return array($finale, $string);
//return $origine;
}
else if ($nombre_ligne_fichier > 6)
{
//étape 1
//$string = "<span id='cacher".$id."' style='display: none;'>";
$string = "<span id=\"cacher".$id."\" style=\"display: none;\">";
$origine = str_replace_occurence('<br/>', $string, $origine, 5);
//étape 2
$fin = $origine . "</span> <a HREF='javascript: Apparait(".$id.");' id='plus".$id."' style='bcolor blue; text-decoration: none; font-size: 12px;' > lire la suite (".$nombre_ligne_fichier." l.)</a> <a HREF='javascript: Disparait(".$id.");' id='moins".$id."' style='bcolor blue; text-decoration: none; font-size: 12px; display: none;' >Moins (".$nombre_ligne_fichier." l.)</a>";
$finale = str_replace($origine, $fin, $origine);
return array($finale, $string);
}
}
}
?>
[/code]
C'est simple toutes les partie de ces fonction qui utilisent des array (y compris des return) ne fonctionnent pas quand j'appel la page en ajax. En revanche quand j'appelle la page normalement ça marche.