monkeybidz Posted June 6, 2010 Share Posted June 6, 2010 I have a VAR that results in text like: "This is my sample result string" How can I make it so it results like so : "This+is+my+sample+result+string" The var is: $row[title] The code is located below: $query = "SELECT url, title, description FROM mylinks ORDER BY RAND() LIMIT 0, 1000"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ echo "<a href=\"http://www.clickraider.com/search.php?query={$row['title']}&search=1\">{$row['url']}</a><br>" . "{$row['title']} <br>" . "ClickRaider Results: {$row['description']} <br><br>"; } Link to comment https://forums.phpfreaks.com/topic/204027-how-to-add-a-sign-between-words/ Share on other sites More sharing options...
teynon Posted June 6, 2010 Share Posted June 6, 2010 If you wanted to convert spaces to a character, you could use preg, but since you are trying to prep it for a browser in your example, I would use urlencode. urlencode($var); Link to comment https://forums.phpfreaks.com/topic/204027-how-to-add-a-sign-between-words/#findComment-1068627 Share on other sites More sharing options...
monkeybidz Posted June 6, 2010 Author Share Posted June 6, 2010 I used string_replace instead, but you lead me in the righ direction. I replaced: {$row['title']} With: ".str_replace(" ","+",$row['title'])." Thanks a Milllion. Link to comment https://forums.phpfreaks.com/topic/204027-how-to-add-a-sign-between-words/#findComment-1068651 Share on other sites More sharing options...
Alex Posted June 6, 2010 Share Posted June 6, 2010 urlencode is a better choice because if there are other characters that need to be changed to work in the URL it will change them as well. Link to comment https://forums.phpfreaks.com/topic/204027-how-to-add-a-sign-between-words/#findComment-1068654 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.