dse84825 2011-10-12 13:56
浏览 18
已采纳

Php重现一个js脚本(转换为php脚本)[关闭]

i would like to reproduce/convert this js script to a php script, is there anyone can help me? i think i need preg_replace() in php and i'm really not good with it :/

this is my js simple script:

wysiwyg_val = $('.wysiwyg textarea').val()
.replace(/
/g, "<br>")
.replace(/<br>/g,'[br]')
.replace(/\</g,'&lt;')
.replace(/\>/g,'&gt;')
.replace(/\{code\}/g, '<pre><code>')
.replace(/\{\/code\}/g, '</code></pre>')
.replace(/\{strong\}/g, '<strong>')
.replace(/\{\/strong\}/g, '</strong>')
.replace(/\{italic\}/g, '<i>')
.replace(/\{\/italic\}/g, '</i>')
.replace(/\{title\}/g, '<h2>')
.replace(/\{\/title\}/g, '</h2>')
.replace(/\{subtitle\}/g, '<h3>')
.replace(/\{\/subtitle\}/g, '</h3>')
.replace(/\[br\]/g,'<br>');

the wysiwyg_val, after is escaped, is passed via Ajax to a php page which can take it as $_POST['text']

  • 写回答

2条回答 默认 最新

  • duangong937906 2011-10-12 14:04
    关注
    $wysiwyg_val = 'xyz'; // your WYSIWYG input
    
    $replacements = array(
        array('/
    /g', "<br>"),
        array('/<br>/g', '[br]'),
        array('/\</g','&lt;'),
        // and so forth.
    );
    
    foreach ($replacements as $replacement) {
        $wysiwyg_val = preg_replace($replacement[0], $replacement[1], $wysiwyg_val);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line