3

How to echo-ing decoded url from GET method on php,

i have this link:

localhost/whatsapp?text=Hello%2C%20Who%20are%20U%3F%0AName%3A%20%0AAddress%3A%20%0AAge%3A%20

with this code

$text = $_GET['text'];
header("Location: https://web.whatsapp.com/send?phone=00000000&text=".$text);

but get error

Warning: Header may not contain more than a single header, new line detected in index.php on line

1

2 Answers 2

4

When you retrieve values from $_GET, they are URL decoded. If you want to pass it back, you need to encode it again, so that newlines, spaces and other weird characters gets encoded. Use urlencode($text) for this.

$text = $_GET['text'];
header("Location: https://web.whatsapp.com/send?phone=00000000&text=".urlencode($text));
Sign up to request clarification or add additional context in comments.

6 Comments

on whatsapp write as Hello,+Who+are+U? Name:+ Address:+ Age:+ how to remove "+" char?
That's the encoded URL. To decode it, you use urldecode() on it after its sent (on the receiving end). You need to check what sort of parameter you can send to their text.
I want to convert from this link localhost/wa-gen/?text=Hello%2C%20Who%20are%20U%3F%0AName%3A%20%0AAddress%3A%20%0AAge%3A%20 to https://web.whatsapp.com/send?phone=00000000&text=Hello%2C%20Who%20are%20U%3F%0AName%3A%20%0AAddress%3A%20%0AAge%3A%20 so echoing exactly same to $text, but the retrun is diffrent when i use urldecode()
I think whit urlencode() it will remove %20 to + how to exactly echoing same variable without converting %20 to +
rawurlencode() would parse spaces as %20, while urlencode() parses spaces as +. Might want that function instead.
|
0

You will have to parse the incoming encoded URL before adding the correct part to the new URL, such as:

<?php
    $url = 'localhost/wa-gen/?text=Hello%2C%20Who%20are%20U%3F%0AName%3A%20%0AAddress%3A%20%0AAge%3A%20';

    $newURL = "https://web.whatsapp.com/send?phone=00000000&".parse_url($url, PHP_URL_QUERY);
?>

Parse_url is very good at extracting pieces from a given URL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.