dadamssg Posted April 13, 2009 Share Posted April 13, 2009 how do i get php/mysql to recognize spaces?..i put the data im storing through a clean and trim function and then output it with nb2lr and stripslashes, but it will only recognize one space...ex. i can type "blah blah b blah" and it will output "blah blah b blah" Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 13, 2009 Share Posted April 13, 2009 That's because in HTML multiple spaces are reduced to a single space. You would need to use a non-breaking-space - http://www.w3schools.com/HTML/html_entities.asp Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808392 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Author Share Posted April 13, 2009 so should i use something like substr_replace() and replace all " " with  ? would that be the best way to go about doing that? Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808399 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 or wrap it in a pre tag. or a nobr tag. or with css: white-space: nowrap; Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808427 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Author Share Posted April 13, 2009 will something like that still recognize if the user presses enter to get a line break? Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808680 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 I know for sure the pre tag recognizes line breaks. Not 100% about nobr or the css, but I think they just stop whitespace and hyphens from being eligible for line breaks (so in other words, a \n should be recognized). Just to note: the nobr is netscape proprietary and not an official tag, though most browsers seem to support it (even IE). Also I don't think earlier versions of IE support the css attribute (I think IE7+ does. Pretty sure IE6 does not). Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808694 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Author Share Posted April 13, 2009 im not exactly sure what you mean when you say "pre tag". Could you clarify what you're talking about please? Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808698 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 <pre> something here la la lah more something </pre> It stands for pre-formatted Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808705 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Author Share Posted April 13, 2009 i see...so does mysql recognize the spaces? if so then all i would have to do is output the data like so? echo "<pre>".$row['data']."</pre>"; or will i have to input it like so ? $data = "<pre>".$_POST['data']."</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808715 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 It depends on what data type you set your mysql column to. afaik none of them will strip out extra space internal to your data, but depending on what type you use, it may pad the end of the string with extra space to reach the length you set it to be. For example, If you set it to a column type of fixed width (like char(50)) and you have 20 char string, it will not strip out internal extra spaces, but it will pad the end of the string to make it 50 chars long. If you have a variable width column type like varchar(50), it will not pad the string. If you use a binary data type column like blob, it will store it as is (in binary format though). So to make a long story short, you don't really have to worry about what happens to your data when it's going in to sql, except you might have to trim it if you use a fixed length data type. Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808734 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Author Share Posted April 13, 2009 its set to text...so yeah i think i just need to output it between the pre tag, i just put some text with multiple spaces and linebreaks into the db and it get stored the same way i put it in, just doesn't output right...so thanks. ill try to the pre tag and hopefully thatll work Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808746 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Author Share Posted April 13, 2009 that did it! now i just gotta figure out how to change the font/color of the text...made the text look stretched...hmmm Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808754 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 yeah the default font for pre tag is monospace. You should be able to hook font styling to it. Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808762 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Author Share Posted April 13, 2009 yeah...this has nothing to do with spaces but maybe someone could help me with this since i already have a thread open. i have an inbox for messages in a table...and i want to make the subject clickable, but they have the option to leave the subject blank if they have something in the actual message...but if they leave the subject blank...theres nothing to click. so i thought i would try to make the table cell clickable but that didn't work. heres what i got $subject = ucwords($row['subject']); echo "<td><h3><a href = showmessage.php?ms={$row['messageid']}>{$subject}</a></h3></td>"; any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808769 Share on other sites More sharing options...
.josh Posted April 13, 2009 Share Posted April 13, 2009 better off asking that in the javascript forum... Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808775 Share on other sites More sharing options...
thebadbad Posted April 13, 2009 Share Posted April 13, 2009 You should be able to make it clickable with javascript (yeah, I know, wrong forum): $subject = ucwords($row['subject']); echo "<td onclick=\"window.location.href = 'showmessage.php?ms={$row['messageid']}';\" style=\"cursor: pointer;\"><h3><a href=\"showmessage.php?ms={$row['messageid']}\">{$subject}</a></h3></td>"; Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808785 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Author Share Posted April 13, 2009 hey thanks...ill have to try that Quote Link to comment https://forums.phpfreaks.com/topic/153818-solved-recognize-spaces/#findComment-808796 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.