【问题标题】:How to keep textarea from duplicating text when saved in PHP?保存在 PHP 中时如何防止 textarea 重复文本?
【发布时间】:2011-04-13 19:28:55
【问题描述】:

抱歉,我对 PHP 一无所知,我想做的是在我的 WordPress 网站上有一个选项页面,您可以在其中在文本区域中输入代码,然后它会显示在我的页面部分中除了我试图让<style type=\"text/css\"></style> 出现在文本区域内而不必手动将它们放在那里之外,一切都在工作(可能不正确但工作)。这就是我现在拥有的方式,但是当我保存时样式标签会不断重复。例如<style type=\"text/css\"></style> 保存然后它会在文本区域中显示<style type=\"text/css\"></style><style type=\"text/css\"></style>

array(  'name' => 'Header CSS ',
        'desc' => 'Add your own css between the <style> tags.',
        'id' => 'nrg_header_css',
        'type' => 'textarea'),

<textarea name="nrg_header_css" rows=8 style="width: 98%;"><?php echo stripslashes(nrg_get_option_setting('nrg_header_css')); ?><style type=\"text/css\"></style></textarea>
        <br />
        <p class="submit">
         <input name="<?php echo($actname); ?>" type="submit" value="<?php echo($flabel); ?>" />    
         <input type="hidden" name="action" value="<?php echo($actname); ?>" />
        </p>

谢谢

【问题讨论】:

  • 你看错了。您不应将占位符放入 textarea 并保存。只在真正需要的时候输出脚本标签。

标签: php wordpress textarea


【解决方案1】:

尝试改变:

<textarea name="nrg_header_css" rows=8 style="width: 98%;">
<?php echo stripslashes(nrg_get_option_setting('nrg_header_css')); ?>
<style type=\"text/css\"></style>
</textarea>

<textarea name="nrg_header_css" rows=8 style="width: 98%;">
<?php
$content = stripslashes(nrg_get_option_setting('nrg_header_css'));
if($content=='')
{
    echo '<style type=\"text/css\"></style>';
}
else
{
    echo $content;
}
?>
</textarea>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-31
    • 1970-01-01
    • 1970-01-01
    • 2015-02-20
    • 1970-01-01
    • 2018-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多