Footnotes in PHP

Hi, I am turning to you this time to ask for help with footnotes. I now have an article with php code in .txt format and I am editing it using Powershell. Everything has been successful except for the last thing. That is that I would need it to edit or add the following to each occurrence of <li> or <sup>: "<a id="note_X"> what should happen when X should increase by 1 after each replacement, i.e. for example the first one is found "<li>" and will be replaced by "<li><a id="note_1">", the next occurrence will be replaced by <li><a id="note_2"> and so on. I have tried these two solutions, but neither works:

if ($inFootnotesSection) { 

    if ($line -match "<li>") { 

        $line = $line -replace "(<li>)", "`$1<a id=`"note_$noteCounter`"></a>" 

        $noteCounter++ 

    } 

    if ($line -match "<sup>") { 

        $line = $line -replace "(<sup>)", "<a id=`"note_$noteCounter`"></a>`$1" 

        $noteCounter++ 

    } 

}
if ($inFootnotesSection -and $line -match "<li>|<sup>") { 

    if ($line -match "<li>") { 

        $line = $line -replace "(<li>)", "`$1<a id=`"note_$noteCounter`"></a>" 

    } 

    if ($line -match "<sup>") { 

        $line = $line -replace "(<sup>)", "<a id=`"note_$noteCounter`"></a>`$1" 

    } 

    $noteCounter++ 

} 

I’m still attaching the exact wording of the part of the text that doesn’t correct me:

... study.
</p>
<h1>Footnotes</h1>
<ol>
<li>Acknowledging the... 

Would anyone know what to do about it? I can’t figure out what I’m doing wrong.

What is the problem with your output? That might help us give you some direction…

From first glance, I don’t think you need the backtick in front of your variable names. If the output actually includes “$1”, that would be somewhere to look.

Thanks for your answer. With the rest of my code, it correctly modifies the title, but no longer just adds: <a id="note_1">" correctly. So this is what I get as a result:

...study.</p>
<h2 style="text-align: center;">Footnotes</h2>
<ol>
<li>Acknowledging the...

from that text:

... study.
</p>
<h1>Footnotes</h1>
<ol>
<li>Acknowledging the...

And I’m supposed to replace the backtick with something? I’m really not sure about this, so I’m afraid I’ll break it completely.

Guess I’m still missing something, but the little test below works for me. I created a txt with the input you included above (and a couple of extra lines) and then ran it through a simplified loop. I think it came out like you wanted it to.

Input file (C:\temp\XMLTest.txt):

... study.
</p>
<h1>Footnotes</h1>
<ol>
<li>Acknowledging the...
<li>Second note
<li>Third note

Script:

$tmp = Get-content C:\temp\XMLTest.txt
$noteCounter = 1
$tmp | foreach-object { 
    $line = $_
    if ($line -match "<li>") { 
        $line -replace "(<li>)", "<li><a id=`"note_$notecounter`"></a>`$1" 
        $noteCounter++
    }
}

Output:

<li><a id="note_1"></a><li>Acknowledging the...
<li><a id="note_2"></a><li>Second note
<li><a id="note_3"></a><li>Third note

If you’re still having problems, post a good chunk of your input and of your script.