Javascript PHP和JS帮助:函数不';不接受用echo粘贴的参数
下面是我用来通过PHP粘贴HTML的长代码行:Javascript PHP和JS帮助:函数不';不接受用echo粘贴的参数,javascript,php,Javascript,Php,下面是我用来通过PHP粘贴HTML的长代码行: echo "<h2 style=\"color: white!important; background: black!important; border: 4px black solid!important;\">", $p_name, "<span id=\"portfolio-", $p_id, "\" onclick=\"expandToggle(this);\" style=\"float: right; padding
echo "<h2 style=\"color: white!important; background: black!important; border: 4px black solid!important;\">", $p_name, "<span id=\"portfolio-", $p_id, "\" onclick=\"expandToggle(this);\" style=\"float: right; padding-right: 10px; cursor: pointer;\">+</span>", "<span onmouseover=\"getNotify(this, true)\" onmouseout=\"getNotify(this, false)\" onclick=\"window.open(",$p_get,")\" style=\"float: right; cursor: pointer; padding-right: 15px;\">⬇</span></h2>";
如何修复此问题?url周围似乎有新行(
\n
)字符
echo "<h2 style=\"color: white!important; background: black!important; border: 4px black solid!important;\">",
$p_name, "<span id=\"portfolio-", $p_id, "\" onclick=\"expandToggle(this);\" style=\"float: right; padding-right: 10px; cursor: pointer;\">+</span>",
"<span onmouseover=\"getNotify(this, true)\" onmouseout=\"getNotify(this, false)\" onclick=\"window.open('",str_ireplace("\n", "", $p_get),"')\" style=\"float: right; cursor: pointer; padding-right: 15px;\">⬇</span></h2>";
更新:由于您的代码可能很难阅读,因此很难理解,这里是一个更好的格式化解决方案
printf(
'<h2 style="color: white!important; background: black!important; border: 4px black solid!important;">
%s
<span id="portfolio-%d" onclick="expandToggle(this);" style="float: right; padding-right: 10px; cursor: pointer;">+</span>
<span onmouseover="getNotify(this, true)" onmouseout="getNotify(this, false)" onclick="window.open(\'%s\')" style="float: right; cursor: pointer; padding-right: 15px;">⬇</span>
</h2>',
$p_name, $p_id, str_replace("\n", "", $p_get)
);
printf(
'
%
+
⬇
',
$p_name、$p_id、str_replace(“\n”、“”、$p_get)
);
哦,我这边有个错误。我使用一个文本文件从中获取信息,然后循环一个数组并粘贴到网站上。我使用explode()php函数来划分项目部分及其描述,其中有nl。是的。谢谢使用PHP\u EOL
而不是“\n”@LexLaiden Cheers。URL不也应该用引号括起来吗?据我所知,不是。那不可能是对的。@Davor是的。检查内部html部分。
window.open('",str_ireplace("\n", "", $p_get),"')
printf(
'<h2 style="color: white!important; background: black!important; border: 4px black solid!important;">
%s
<span id="portfolio-%d" onclick="expandToggle(this);" style="float: right; padding-right: 10px; cursor: pointer;">+</span>
<span onmouseover="getNotify(this, true)" onmouseout="getNotify(this, false)" onclick="window.open(\'%s\')" style="float: right; cursor: pointer; padding-right: 15px;">⬇</span>
</h2>',
$p_name, $p_id, str_replace("\n", "", $p_get)
);