When I try to pass to a separate web page a value that has a space, that called web page truncates the value from the instance of the space. Of course, the solution is to replace the space with “%20”. But the problem is that the value being passed comes from another variable (say from an item in a database table’s row). There must be a way to replace all instances of space in each variable’s value.
Solution: Use the str_replace function to replace all instances of space with ‘%20’.
Other ways worth considering are:
$var = ‘hello world ‘;
$var1 = preg_replace(‘/\s/’, ‘%20’, $var);
//$var1 should contain “hello%20world%20%20”
$var2 = urlencode($var);
//$var2 should contain “hello+world++”