Canman2005 Posted March 12, 2007 Share Posted March 12, 2007 Hi all I have a simple sql statement that pulls a list of files from a sql table, I then print the name of each filename using print $rows[filename]; This works fine, unless a filename has a spae in it and then it reads everything up to the space. For example, a filename which prints ok looks like image1.jpg but if there is a space for example image 1.jpg then it prints image and forgets everything after the space. Is there a fix for this? Thanks Dave Link to comment https://forums.phpfreaks.com/topic/42411-solved-problem-with-spaces/ Share on other sites More sharing options...
papaface Posted March 12, 2007 Share Posted March 12, 2007 just do: $rows[filename] = preg_replace(" ", "_", $rows[filename]); That should work (it will put a _ where ever a space is), but im not an expert as regex and things like this. Link to comment https://forums.phpfreaks.com/topic/42411-solved-problem-with-spaces/#findComment-205731 Share on other sites More sharing options...
Barand Posted March 12, 2007 Share Posted March 12, 2007 It would help if you showed us the code that is having this effect Link to comment https://forums.phpfreaks.com/topic/42411-solved-problem-with-spaces/#findComment-205733 Share on other sites More sharing options...
Canman2005 Posted March 12, 2007 Author Share Posted March 12, 2007 Hi My code looks like if ($rows[type] == 'application/pdf' || $rows[type] == 'text/plain') { print '<p style=margin-top:5px><strong><a href=file_uploads/'.$rows[filename].' target=_blank>View \ Download File</a></strong></p>'; } So if a filename has a space in it, then it ignore everything after the space Does that help? Link to comment https://forums.phpfreaks.com/topic/42411-solved-problem-with-spaces/#findComment-205743 Share on other sites More sharing options...
papaface Posted March 12, 2007 Share Posted March 12, 2007 its your bad coding lol. should be: print '<p style=margin-top:5px><strong><a href="file_uploads/'.$rows[filename].'" target="_blank">View \ Download File</a></strong></p>'; Link to comment https://forums.phpfreaks.com/topic/42411-solved-problem-with-spaces/#findComment-205745 Share on other sites More sharing options...
Canman2005 Posted March 12, 2007 Author Share Posted March 12, 2007 oooppps Thanks Link to comment https://forums.phpfreaks.com/topic/42411-solved-problem-with-spaces/#findComment-205758 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.