Re: Cleaning bad characters from var

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



John Nichel wrote:
Paul Nowosielski wrote:

I wrote a function to do this for our product descriptions when sending them in a XML doc to certain vendors. It's old, crude, but you're welcome to it.
<snip function that uses regular expressions for simple string replacements>


Using regular expressions for that is a very bad idea. You're using regular expressions for simple string matches, which is going to be much slower than just using the simple string replace functions. It even warns you against doing what you're doing in the manual.

Here's a function that demonstrates replacing several characters with something else

function replaceChars($string)
{
    $find_array = array("a", "b", "c");
    $replace_array = array("apple", "banana", "carambola");

    return str_replace($find_array, $replace_array, $string);
}

You can, of course, throw other string processing functions in there.

Regards, Adam Zey.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux