Bonjour, je ne sais pas comment intitulé cette demande.
En gros je souhaite retirer les balises <br /> après chaque balise html choisie.
jusque la pas de problème voici mon code:
Là où çà devient compliqué c'est que les balises peuvent avoir des arguments comme par exemple <a href="google.com">.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 $replace = array( // Balise table "<table><br />", // Ouverture tableau "</table><br />", // Fermeture tableau "<tr><br />", //Ouverture de ligne de tableau "</tr><br />", //Fermeture de ligne de tableau "<td><br />", //Ouverture de colonne de tableau "</td><br />", //Fermeture de colonne de tableau "<th><br />", //Ouverture de colonne titre de tableau "</th><br />", //Fermeture de colonne titre de tableau //Paragraphe "<p><br />", "</p><br />", //Titre "<h1><br />", "</h1><br />", "<h2><br />", "</h2><br />", "<h3><br />", "</h3><br />", "<h4><br />", "</h4><br />", //Balise en une ligne: "<a><br />", // Lien "<b><br />", // Text en gras "<i><br />", // text en italique ); $baliseok = '<b><i><table><tr><td><th><h1><h2><h3><h4><br><a><font><xmp><img>'; $text = strip_tags($text, $baliseok); $newreplace = array(); foreach($replace as $key => $value){ // On nétoie automatoquement le tableau replace $newreplace[$key] = str_replace("<br />", "", $value); } $text = str_replace($replace, $newreplace, $text); return($text);
Saviez vous comment je pourrais sélectionner également ses formes de balise ?
J'ai essayer en intègrent (.*) comme suit:
Mais cela ne fonctionne pas.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 $replace = array( // Balise table "<table><br />", // Ouverture tableau "</table><br />", // Fermeture tableau "<tr><br />", //Ouverture de ligne de tableau "</tr><br />", //Fermeture de ligne de tableau "<td><br />", //Ouverture de colonne de tableau "</td><br />", //Fermeture de colonne de tableau "<th><br />", //Ouverture de colonne titre de tableau "</th><br />", //Fermeture de colonne titre de tableau //Paragraphe "<p><br />", "</p><br />", //Titre "<h1><br />", "</h1><br />", "<h2><br />", "</h2><br />", "<h3><br />", "</h3><br />", "<h4><br />", "</h4><br />", //Balise en une ligne: "<a(.*)><br />", // Lien "<b><br />", // Text en gras "<i><br />", // text en italique );
Bien à vous
Partager