Jump to content

Special chars, encoding and decoding a page title with an ampersand (for sharing)


a-ok
 Share

Recommended Posts

I'm curious.

In order to share a link via Twitter you do something like the following

https://twitter.com/intent/tweet?text=<?php echo $page->title; ?>&url=<?php echo $page->httpURL; ?>&via=processwire

And in most instances that works fine. However, if the page title has an ampersand in it then it breaks the text. I've looked at using $sanitizer for this but doesn't seem to do the job. What I've found out works is the following:

htmlspecialchars(urlencode(html_entity_decode($page->title, ENT_COMPAT, 'UTF-8')), ENT_COMPAT, 'UTF-8');

However I'm wondering if there is a way to use $sanitizer to achieve this? Or some other way with the API?

Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...