开发者

Insert special characters to a string for web address

Im fetching an array from my sql database, but开发者_Python百科 the string has spaces in it (ie B54DT45 GDT4563 HaK7698).

This needs to go into a webadress like %30B54dT45%20 so that the outcome is

Here is my code: $pid = mysql_query("SELECT cPushID FROM tblUsers WHERE intUserID='20' AND Length(cPushID) > 70 AND cAlerts = 'All'"); $url = rawurlencode(""); $msg = "test";

file_get_contents("http://domain/push.php?msg=$msg&to=$url");

The string in the database is something like as an example. That exact string needs to be send to the push.php script on the remote server for it to run correctly


rawurlencode()

because the space must be %20 according to the question.

edit: the question wasn't very clear, but to add < and > before encoding, just do

rawurlencode("<$txt>");

edit: the question has evolved into a mysql question, here's a short answer

$res = mysql_query("SELECT `this` FROM `that`");
$row = mysql_fetch_row($res);
$this = $row[0];

or

$res = mysql_query("SELECT `this` FROM `that`");
$row = mysql_fetch_assoc($res);
$this = $row['this'];


urlencode or rawurlencode, depending on if you want spaces as + or %20.


Use urlencode then urldecode it before inserting it to the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜