dpvomqeu396484 2019-06-24 08:24
浏览 62

在标签之间进行文件,搜索和替换

desolate for my bad english

I have a file with many products example below, I am looking for a solution to modify the data example if several rename the 2nd model by and and and etc ...

<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>

I am not good at php // rename all models in two mode

$text=fopen($filename,'r') or die("Fichier manquant"); 
$contenu=file_get_contents($filename);
$contenu = str_replace("</model>
<model>", "</model>
<model2>", $contenu); 
fclose($text); 
$text2 = fopen($filename, 'w+') or die("Fichier manquant"); 
fwrite($text2, $contenu); 
fclose($text2);

I know we have to look between the tags and replace the result but I'm not good in PHP

the result I'm looking for

<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>
<model3>
    <id>43077_27</id>
    <parent_id>43077</parent_id>
    <size>27</size>
    <availability>0</availability>
    <ean>7438632273036</ean>
</model3>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
    • ¥15 C# datagridview 单元格显示进度及值
    • ¥15 thinkphp6配合social login单点登录问题
    • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配