Page 1 of 1

Convert spaces to  

Posted: Tue Dec 22, 2009 7:53 pm
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

Re: Convert spaces to  

Posted: Tue Dec 22, 2009 8:35 pm
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

Re: Convert spaces to  

Posted: Tue Dec 22, 2009 8:49 pm
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.

Re: Convert spaces to  

Posted: Wed Dec 23, 2009 1:42 am
by requinix
Be really careful with this - especially with long strings. The HTML entity for a space is not  .