Convert spaces to  

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
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Convert spaces to  

Post by alex.barylski »

Do I have to do this manually for characters? I thought htmlentities or htmlspecialchars would do this but apparently things like hypen and space don't get converted. I don't really want to introduce another function into the mix to properly encode strings but it looks like I have to???

Cheers,
Alex
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: Convert spaces to  

Post by daedalus__ »

im not sure if either of those functions will do it but you may want to look at this comment:

http://us.php.net/htmlentities#84327

also look at this function. maybe you can specify a translation table. if there isn't a table that converts spaces then perhaps you could modify an existing one or create your own. :)

http://us.php.net/manual/en/function.ge ... -table.php
invisibled
Forum Contributor
Posts: 112
Joined: Sun Apr 29, 2007 3:35 pm
Location: New Westminster

Re: Convert spaces to  

Post by invisibled »

you could use str_replace.

$text = str_replace(" ", " ", $_POST['text']);

the example above is assuming a user inputs text into a form element named "text" and submits the form. the first param defines what char to replace, the second tells it what to replace with, and the third is your source.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Convert spaces to  

Post by requinix »

Be really careful with this - especially with long strings. The HTML entity for a space is not  .
Post Reply