extrovertive Posted August 27, 2006 Share Posted August 27, 2006 I have a thing on my site where a user can upload a file to a folder. Then the url to that file will be sent to me.However, sometimes the filename a user uploads has a space in it when sending to my email.Ex.http://domain.com/user/my file.docThus, the url gets cut-off after the "my"How do I make it so that if a user uploads a filename with space, it will still be a clickable link?I tried urlencode but then I get something like http://domain.com/user/my+file.doc which is an invalid file. But http://domain.com/user/my%20file.doc works. How do I make it do that? Quote Link to comment https://forums.phpfreaks.com/topic/18787-spaces-in-url-to-20/ Share on other sites More sharing options...
Orio Posted August 27, 2006 Share Posted August 27, 2006 you can use:str_replace(" ","%20",$url);Orio. Quote Link to comment https://forums.phpfreaks.com/topic/18787-spaces-in-url-to-20/#findComment-81041 Share on other sites More sharing options...
wildteen88 Posted August 27, 2006 Share Posted August 27, 2006 or use [url=http://php.net/urlencode]urlencode[/url] Quote Link to comment https://forums.phpfreaks.com/topic/18787-spaces-in-url-to-20/#findComment-81075 Share on other sites More sharing options...
onlyican Posted August 27, 2006 Share Posted August 27, 2006 What I do is simular to Orio, although %20 is a whitespaceI usestr_replace(" ","_",$file_name)before uploading Quote Link to comment https://forums.phpfreaks.com/topic/18787-spaces-in-url-to-20/#findComment-81086 Share on other sites More sharing options...
Orio Posted August 27, 2006 Share Posted August 27, 2006 [quote author=wildteen88 link=topic=105792.msg422754#msg422754 date=1156680893]or use [url=http://php.net/urlencode]urlencode[/url][/quote]He said he use urlencode and it made the spaces to plus ("+").Orio. Quote Link to comment https://forums.phpfreaks.com/topic/18787-spaces-in-url-to-20/#findComment-81106 Share on other sites More sharing options...
kenrbnsn Posted August 27, 2006 Share Posted August 27, 2006 If people would get into the habit of enclosing values of attributes in quotes (double or single depending on the situation), problems like this wouldn't happen. When you surround the URL in quotes, the browser will automagically do the conversion for you.Since you didn't tell us what type of HTML tag you're trying to use, I will assume it's a "<a>" for this illustration:In your case:[code]<?php echo '<a href="http://domain.com/user/my file.doc">'; ?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/18787-spaces-in-url-to-20/#findComment-81108 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.