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条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器