Bonjour,

j'ai un fichier avec plein de produits exemple plus bas, je cherche une solution pour modifier les données exemple si plusieurs <model>renommer le 2 eme model par <model2> et </model2> et <model3> et </model3> etc...

comme ceci
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
     <model>
                <id>43077_26</id>
                <parent_id>43077</parent_id>
                <size>26</size>
                <availability>0</availability>
                <ean>7438632274965</ean>
            </model>
            <model2>
                <id>43077_27</id>
                <parent_id>43077</parent_id>
                <size>27</size>
                <availability>0</availability>
                <ean>7438632273036</ean>
            </model2>
exemple
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
40
41
42
43
    <product>
        <product_id>43077</product_id>
        <product_model><!--[CDATA[WH2-P17022704279LF_FLATIRON_1750]]--></product_model>
        <product_maincategory>Femme</product_maincategory>
        <product_subcategory>Jeans</product_subcategory>
        <product_category>Femme Jeans</product_category>
        <product_manufacturer><!--[CDATA[Phard]]--></product_manufacturer>
        <product_name><!--[CDATA[Phard Femme Jeans]]--></product_name>
        <product_description><!--[CDATA[<b-->Marque: Phard<br><b>Sexe:</b> Femme<br><b>Typologie:</b> Jeans<br><b>Fabriqué en:</b> China<br><b>Saison:</b> Toutes les saisons<br><br><b>DÉTAILS DU PRODUIT</b><br>• <b>Couleur:</b> bleu<br>• <b>Fermeture:</b> zip et bouton<br>• <b>Poches:</b> poches frontales et arrières<br>• <b>Autres détails:</b> -effet déchiré -effet usé <br><br><b>COMPOSITION ET MATIÈRE</b><br>• <b>Composition:</b> -100% coton <br>• <b>Matière:</b> jeans<br>•  <b>Lavage:</b> en machine à 30°]]&gt;</product_description>
        <product_price>110.00</product_price>
        <product_price_special>9</product_price_special>
        <product_image_1>/images/large1/1750_TINTA_UNITA_186500CEACAF168C0FEA4C481730511C_BLU.jpg</product_image_1>
         <product_image_2>/images/large2/1750_TINTA_UNITA_186500CEACAF168C0FEA4C481730511C_BLU.jpg</product_image_2>
         <product_image_3>/images/large3/1750_TINTA_UNITA_186500CEACAF168C0FEA4C481730511C_BLU.jpg</product_image_3>
        <product_quantity>8</product_quantity>
        <product_sizes>
            <model>
                <id>43077_26</id>
                <parent_id>43077</parent_id>
                <size>26</size>
                <availability>0</availability>
                <ean>7438632274965</ean>
            </model>
            <model>
                <id>43077_27</id>
                <parent_id>43077</parent_id>
                <size>27</size>
                <availability>0</availability>
                <ean>7438632273036</ean>
            </model>
            <model>
                <id>43077_28</id>
                <parent_id>43077</parent_id>
                <size>28</size>
                <availability>0</availability>
                <ean>7438632273038</ean>
            </model>
        </product_sizes>
        <product_weight>0.500</product_weight>
        <product_colour><!--[CDATA[bleu]]--></product_colour>
        <product_madein><!--[CDATA[CHINA]]--></product_madein>
        <product_season>2</product_season>
    </product>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
$text=fopen($filename,'r') or die("Fichier manquant"); 
$contenu=file_get_contents($filename);
$contenu = str_replace("</model>\n<model>", "</model>\n<model2>", $contenu); // mais me rennome tout les model en model deux
fclose($text); 
$text2 = fopen($filename, 'w+') or die("Fichier manquant"); 
fwrite($text2, $contenu); 
fclose($text2);