如何让 php 在从表单提交的某些内容的每一侧写入


How do i make php write <div> tags on each side of some content that gets submitted from a form?

标签。

我试图让PHP在从表单提交的内容的每一侧编写标签,以便通过css格式化它。我已经尝试过preg_replace,但我不确定我是否正确使用它。有什么建议吗?

编辑:找到了问题的解决方案!对于任何想知道的人,我用了str_replace

$newline.='</li>';
}
else{
    $newline.=$line;   // legger til melding i tillegg til hva som ligger fra før
    $div = array($newline);
    $tagger = array('<li class="innlegg">'.$newline);
}
}
$newline2 = str_replace($div, $tagger, $newline);

我要去的脚本看起来像这样:

$sidet = $_POST['sidet']; 
$melding = $_POST['Melding']; 
$insertPos=0;  


$file=fopen("htmltest.html","r+") or exit("Error occurd"); 
while (!feof($file)) { 
$line=fgets($file);
if (strpos($line, '<body>')!==false) {
$insertPos=ftell($file);    
$newline = $melding;
}
else{
$newline.=$line;   
}
}

fseek($file,$insertPos);  
fwrite($file,$str);

fclose($file); 
echo "Your submission is recieved and will be posted as soon as possible";
?> 
</body>
</html>
$melding = '<div class="whatever">'.$melding.'</div>';