Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urlencode() does not work

Tags:

php

urlencode

I have a URL like this:

http://x.x.x.x/feedsms?to=$groupName&text=$content"

When I call this url it should send a SMS. I have used file_get_contents() to read the SMS content and urlencode() because of the spaces and special characters:

$url = urlencode("http://x.x.x.x/feedsms?to=$groupName&text=$content");
$urlContent = file_get_contents($url);

The $content is something like this:

F: [email protected] S: Veeam Repoting B: Target: y.y.y.y, Status: Error, Time: 8/22/2015 3:05:30 PM

But I can't call the url:

file_get_contents(): failed to open stream: No such file or directory ... 

Also I used rawurlencode(), but nothing changed.

like image 329
Bayan B Avatar asked Jul 09 '26 19:07

Bayan B


1 Answers

urlencode should be used, as docs says, to encode a string to be used in a query part of a URL. You should not use it on your entire URL but only for every parameter that should be encoded, in your case $groupName and $content. Something like this should do the trick:

$url = "http://x.x.x.x/feedsms?to=" . urlencode($groupName) . "&text=" . urlencode($content);
like image 136
aghidini Avatar answered Jul 12 '26 09:07

aghidini



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!