Insert special characters to a string for web address (PHP question)
I posted this question last week, but I wasn't very clear on what was needed. So I'm reposting right now.
I have a string stored in a database, which looks something like this:
<5u79cfda 4d01ga3a 11c833f9 7b52df2a 7g210252 e21b01fa a73d3463 9ge0e412>
I'm trying to insert this into a web address, but needs to be encoded properly for it to work. I'm running a query to obtain the script:
$result = mysql_query("SELECT cPushID FROM tblUsers WHERE intUserID='20' AND Length(cPushID) > 70");
$pid = mysql_fetch_row($result);
Then trying to insert it into this web address to be 开发者_如何学编程executed:
file_get_contents("http://domain/test.php?msg='Test!'&to=$pid");
How do I properly insert this string into the web address so it will be read properly upon execution.
Thanks for your help.
Use urlencode
.
How about urlencode?
$encoded = urlencode($some_string");
Pass that encoded string to file_get_contents
If you ever need to decode it, use urldecode()
http://php.net/manual/en/function.urlencode.php
You need to urlencode()
your query string in order to safely encode those spaces (and possible angle brackets as well?!)
file_get_contents("http://domain/test.php?msg='Test!'&to=".urlencode($pid));
The query string is automatically decoded when you read $_GET['pid']
精彩评论