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
Convert spaces to
Moderator: General Moderators
-
alex.barylski
- DevNet Evangelist
- Posts: 6267
- Joined: Tue Dec 21, 2004 5:00 pm
- Location: Winnipeg
- daedalus__
- DevNet Resident
- Posts: 1925
- Joined: Thu Feb 09, 2006 4:52 pm
Re: Convert spaces to
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
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
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.
$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
Be really careful with this - especially with long strings. The HTML entity for a space is not .