【发布时间】:2018-07-25 21:27:37
【问题描述】:
我在网上尝试了很多方法来解释这个问题,但没有找到适合我需要的方法。
我想在我的网站上为每个产品创建一个share to whatsapp 链接,包括product name, line-break and link。像这样的:
Product Name [/r/n]
https://....
我正在使用 OpenCart 3。这是 php 端代码:
'whatsapp_text' => $result['manufacturer'] . ' - ' . $result['model'] . ' - ' . $result['name']
. $this->encodeURIComponent('\r\n' . $this->url->link('product/product', 'product_id=' . $result['product_id']))
以上代码返回:
https://api.whatsapp.com/send?text=Nurinu%20-%201310%20-%20Bra%5Cr%5Cnhttp%3A%2F%2Fwww.myweb.com%2Findex.php%3Froute%3Dproduct%2Fproduct%26amp%3Bproduct_id%3D61
根据此页面 (https://github.com/kriskbx/whatsapp-sharing/issues/16#issuecomment-294854157) 可以使用window.encodeURIComponent(whatsappMessage) 来拥有line-break,但我不知道如何将它与我的 php 代码结合使用或在 html 端使用它:
<a href="https://api.whatsapp.com/send?text={{ product.whatsapp_text }}" data-action="share/whatsapp/share">Whatsapp</a>
更新
我忘了包含函数(encodeURIComponent):
function encodeURIComponent($str) {
$revert = array('%21'=>'!', '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')');
return strtr(rawurlencode($str), $revert);
}
【问题讨论】:
-
'\r\n'- 这不是换行符。 -
@CBroe:那我应该改用什么?
-
您了解 PHP 语法基础知识……? php.net/manual/en/language.types.string.php
-
这是使用
rawurlencode的输出: 这是输出:Moonlight-263-Bra%5Cnhttp%3A%2F%2Fwww.mysite.com%2Findex.php%3Froute%3Dproduct%2Fproduct% 26amp%3Bproduct_id%3D55 知道如何换行吗? -
阅读我发布的手册链接...并注意用单引号或双引号括起来的字符串之间的区别...
标签: javascript php hyperlink whatsapp encodeuricomponent