space

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

space

Post by nincha »

any tips to show space character thats from Mysql
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please explain in more detail.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Like this?

Code: Select all

<?php
$result = count_chars("You mean something       like this?",0);
// 32 being the code for space...
echo $result[32]; // returns 10
?>
nincha
Forum Contributor
Posts: 191
Joined: Fri Mar 28, 2003 12:30 pm
Location: CA, USA

Post by nincha »

what i meant is that, when somthing like this is saved into Mysql

"my name is bob _____ , look at those spaces _______ when i retrieve this string from Mysql the blank spaces will not show." the lines represent blank spaces.
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

That's because by default anything beyond ' ' will be removed.. So what you can do is add this right before you insert it:

Code: Select all

$_POST['text'] = str_replace(" ","&*nbsp;",$_POST['text']);
This will modify it so that all those spaces and changed into &*nbsp; which is a space, but it doesn't get removed.
Be sure to remove the star between "&" and "nbsp;" i added it so that it was visible
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

That's a smart idea, but that would turn ALL spaces in your text into a straight line. Try it with a very long message, and you'll see what I mean.
Image Image
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

But it does the thing... ;)
wordwrap() it?
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

If there are more spaces than normal, I might try either wordwrap or something like:

Code: Select all

str_replace("  ", " &*nbsp;", $string);
But then again, I've never tried it..
Image Image
tazque
Forum Newbie
Posts: 1
Joined: Mon Sep 15, 2003 3:29 am

Space

Post by tazque »

Hv U try this;

$text = trim($text)
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

trim will only strip whitespace from the begining and end of a string.

http://se.php.net/manual/en/function.trim.php

Mark
Post Reply