skip to Main Content

I’m trying send following URL as parameter to php,

https://boxtext.com/expected-my-list-size-b2b#:~:text=%E2%80%9C1%2C000%20email%20subscribers%20is%20a,monetization%20methods%2C%E2%80%9D%20Smith%20says.

I try to read the URL using

$url = $_REQUEST["new_url"];

echo $url;

This works fine for the URLs without any special characters. If I remove #:~: this part of the URL, it works fine too. But, with these characters, it’s breaking and only displays https://boxtext.com/expected-my-list-size-b2b.

I’ve tried to send this using a JSON object, but not helping.

Can anyone suggest a way around please?

I’ve tried to send this using a JSON object, but not helping.

2

Answers


  1. Chosen as BEST ANSWER

    This is solved, Used Javascript to encode the URL before sending to PHP.

    I was using encodeURI like below encoded_url = encodeURI(v_url);

    so changed that to

    encoded_url = encodeURIComponent(v_url);

    AJAX call to PHP below,

    xmlhttp.open("POST", "php/call.php?long_url=" + encoded_url);


  2. If you want to submit URLs as values in a query you have to urlencode them:

    if(!empty($_REQUEST['newurl']))
        var_dump($_REQUEST['newurl']);
    
    $url = 'https://boxtext.com/expected-my-list-size-b2b#:~:text=%E2%80%9C1%2C000%20email%20subscribers%20is%20a,monetization%20methods%2C%E2%80%9D%20Smith%20says';
    $encoded_url = urlencode($url);
    echo ('<a href="?newurl=' . $encoded_url . '">Click me</a>');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search