简体   繁体   English

在通过Whatsapp的URL共享动态数据时,如何用%20替换空格?

[英]How to replace spaces with %20 while sharing dynamic data through URLs to Whatsapp?

In this code, I have dynamic colleges in my URL through get I am fetching data through URL and I'm using CodeIgniter. 在此代码中,通过获取URL来获取数据以及使用CodeIgniter,我在URL中拥有了动态的大学。

Now, I want to share content with friends through Whatsapp. 现在,我想通过Whatsapp与朋友分享内容。

When I click on Whatsapp link, it redirects me on Whatsapp Web, and after scanning QR code and then send to any friend it shows spaces in my $colleges like abc but I want a%20b%20c . 当我单击Whatsapp链接时,它将重定向我在Whatsapp Web上的位置,并在扫描QR代码然后发送给任何朋友后,它在$colleges显示空格,例如abc,但我需要a%20b%20c

So, how can I do this ? 那么,我该怎么做呢? Please help me. 请帮我。

<a href="https://web.whatsapp.com/send?text=<?php echo base_url(); ?>college/<?php $strings = $college; $collegesss = preg_replace('/\s+/','%20', $string); echo $collegesss; ?>" target="_blank" style="text-decoration:none" data-action="share/whatsapp/share">
    <div style="color: #fff;">
        <i class="fa fa-whatsapp"></i>&nbsp;&nbsp;Whatsapp
    </div>
</a>

You should use urlencode from PHP library. 您应该使用PHP库中的urlencode

Something like that: 像这样:

<a href="https://web.whatsapp.com/send?text=<?php echo base_url(); ?>college/<?php echo urlencode($college); ?>" target="_blank" style="text-decoration:none" data-action="share/whatsapp/share">
    <div style="color: #fff;">
        <i class="fa fa-whatsapp"></i>&nbsp;&nbsp;Whatsapp
    </div>
</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM