douxi3432 2011-04-22 21:19
浏览 63
已采纳

如何从PHP变量中删除不需要的换行符/换行符?

I am getting an error while i am registering php variable to html form element through javascript. Like If In my code there is php variable $edu_notes and i am assigning this variable's value to a html form element that is

<textarea name="1_1_50" id="1_1_50" ></textarea>

and My Javascript code is :

document.getElementById('1_1_50').value = "<?php echo $edu_notes; ?>";

the value of $edu_notes comes from linkedin profile which is :

"First Text Line

Second Text Line"

there is a gap of blank line between its first text line and second text line. And the javascript gives an error that is

unterminated string literal
"First Text line

Javascript is not getting the full value as a string because of blank line. I have tried some php functions like filter_var(),nl2br(),trim() but not resolving this issue. I have also tried to type cast through (string) $edu_notes.

In my source file what i am getting please see screenshot below :

enter image description here

I am doing this type of functionality because all the form elements are coming from database dynamicaly.

  • 写回答

4条回答 默认 最新

  • donglinxi1467 2011-04-22 21:23
    关注
    document.getElementById('1_1_50').value =
        '<?php echo str_replace("
    ", "\
    ", $edu_notes) ?>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真