【问题标题】:Create line break in WhatsApp message在 WhatsApp 消息中创建换行符
【发布时间】:2023-04-07 07:23:01
【问题描述】:

我一直在使用 WhatsApp 分享消息:

whatsapp-button.js

$_u.="Product Name:".$_productName."\n";

$_u.="Sku:".$_productSku."\n";

<a href="whatsapp://send" data-text="<?php echo nl2br($_u); ?>" data-href="" class="wa_btn <?php echo $buttonsize; ?>" style="display:none">Share</a>

如何添加换行符:

我试过\n\r\nPHP_EOL%0D%0A,但它只是显示为文本。

【问题讨论】:

  • 将 \n 替换为 \r\n ;)
  • 尝试使用:PHP_EOL 而不是\n。这对你有用吗?
  • 你确定你没有在你的 a 标签中搞砸了什么? "&lt;?php echo nl2br($_u); ?&gt; Url:"
  • 试试%0D(回车)
  • 如果您尝试使用 PHP_EOL,也不要使用 nl2br()!

标签: php jquery html whatsapp


【解决方案1】:

如果您只想发送包含换行符的文本

use this %0a


link =`whatsapp://send?text=%0a‎Hello%0aWorld`;

如果你想发送一些包含换行符的 url 链接

var encodedURL = encodeURIComponent(some_url);
link =`whatsapp://send?text=${encodedURL}%0a‎Hello%0aWorld`;

现在将此链接嵌入到锚标记中

<a href=link> Click here! </a>

【讨论】:

  • 在 RTL 语言中它停止工作,%0a 打印在消息中并且不添加新行(使用 selenium 而不是 URL)。
【解决方案2】:

要在 WhatsApp 中创建换行符,您可以使用此命令。它工作正常,我正在使用它:

use `%0a`

例如:

smsContain = "*Greetings from  " + cname + " ,%0a %0aM/s. " + txtName.Text + " %0a %0aYour Bill for Advertisement is generated ; %0a %0aBill Date  :-  " + DateTime.ParseExact(dateTimePicker1.Text, "dd/MM/yyyy", null).ToString("dd/MM/yyyy") + " %0a %0aBill no  :-  " + lblBillNo.Text + "  %0a %0aBilling Amount of Rs.  " + lblNet_Amt.Text + " %0a %0aAdvertisement Published in  " + news + " in " + Edi + "  edition,%0a %0aReleased Date : " + DateTime.ParseExact(DateTime.Parse(dt).ToShortDateString(), "dd/MM/yyyy", null).ToString("dd/MM/yyyy") + ".%0a %0aPlease find the Bill attached below, and request you to please  release the payment ASAP. %0a %0a %0aAny descripancy in regards to this Bill to reported to us immediately.%0a %0a %0aAlways at your Service....* ";
                smsContain = smsContain.Replace("&", "+%26+");

【讨论】:

    【解决方案3】:

    【讨论】:

    • 这在其他答案中已经提到了。
    【解决方案4】:

    我有一个可行的解决方案:

    HTML:

    $_u.="Product Name:".$_productName."\n";
    $_u.="Sku:".$_productSku."\n";
    
    <a data-text="<?php echo $_u; ?>" data-link="" class="whatsapp">Share</a>
    

    JS:

               var isMobile = {
                    Android: function() {
                        return navigator.userAgent.match(/Android/i);
                    },
                    BlackBerry: function() {
                        return navigator.userAgent.match(/BlackBerry/i);
                    },
                    iOS: function() {
                        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
                    },
                    Opera: function() {
                        return navigator.userAgent.match(/Opera Mini/i);
                    },
                    Windows: function() {
                        return navigator.userAgent.match(/IEMobile/i);
                    },
                    any: function() {
                        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
                    }
                    };
                    $(document).on("click", '.whatsapp', function() {
                        if( isMobile.any() ) {
    
                            var text = $(this).attr("data-text");
                            var url = $(this).attr("data-link");
                            var message = encodeURIComponent(text) + " - " + encodeURIComponent(url);
                            var whatsapp_url = "whatsapp://send?text=" + message;
                            window.location.href = whatsapp_url;
                        } else {
                            alert("Please share this in mobile device");
                        }
    
                    });
    

    【讨论】:

      【解决方案5】:

      here 中有一个解决方案,基本上是在使用:

      whatsappMessage = window.encodeURIComponent(whatsappMessage)
      

      【讨论】:

        猜你喜欢
        • 2022-06-16
        • 1970-01-01
        • 2021-12-02
        • 2021-06-05
        • 2021-05-16
        • 1970-01-01
        • 1970-01-01
        • 2019-10-21
        • 2021-03-17
        相关资源
        最近更新 更多