在html代码中插入一个字符串

时间:2018-02-01 04:21:14

标签: html css powershell

所以我试图在html代码中插入和添加字符串。我正在做的是从文本中读取一些字符串:

$getTxt = Get-Content -path test.txt

 $getJson.GetType() | Format-Table -AutoSize

foreach ($name in $getJson)
{
    $name
}

然后取出字符串并将它们插入到这个html

<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Stringer</title>

 <link rel="stylesheet" href="http://stylesheet.link">


  <link rel="stylesheet" href="css/style.css">


</head>

<body>

<div class="ticker-wrap">
<div class="ticker">    
<div class="ticker__item">  <img src="image0.jpg" alt="" width="50" height="60"> "<insert text here>"</div>
 </div>


 </div>
 </div>


 </body>
 </html>

如何使用powershell脚本插入文本以创建

的另一个迭代
<div class="ticker__item">  <img src="image#.jpg" alt="" width="50" height="60"> "<insert text here>"</div>

对于文本文件中的每个字符串? (假设它们是字符串中每个项目的图像文件)

1 个答案:

答案 0 :(得分:0)

所以我想出来为了插入代码我基本上把原始的html和json放在test.txt中。 Powershell将如下所示:

$fileName = ""
$getHtml = Get-content -path index.html 
$getJson = Get-Content -path test.txt
$getJson.GetType() | Format-Table -AutoSize
$name = '<div class="ticker">'
$newhtml= ""
[int]$i = 0

foreach ($line in $getHtml)
{    

   $newHtml += $line + "`n"
   write-host "$newhtml"



   if($line -match $name) # if done like this we have to read the text file backwards unless we dump the entire loop before foing to the nextline
    {   
        $s = $line -match $name
        $newHtml += $name +"`n"    
        while($i -lt $getJson.Length)
        {             
    $line =  "  <div class=" + '"ticker__item"' + ">" + "<img src=" + '"image' + $i + '.jpg" ' + "alt=" + '"" ' + "width=" + '"50"' +  " height=" + '"60"' + ">" + $getJson[$i] + "</div>" + "`n"
    $i += 1
    $newHtml += $line
    write-host "$newhtml" 
        }        
}


}