Edit report at https://bugs.php.net/bug.php?id=60974&edit=1
ID: 60974
User updated by: jonathan at scriptwriterthingy dot com
Reported by: jonathan at scriptwriterthingy dot com
Summary: request for function similar to strpbrk but with
replace features
-Status: Analyzed
+Status: Closed
Type: Feature/Change Request
Package: *General Issues
Operating System: Linux/CentOS
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Ah, somehow I missed that. Thanks, I think that's pretty much what I was hoping
for.
Previous Comments:
------------------------------------------------------------------------
[2012-02-03 21:05:10] [email protected]
I said strtr() not strstr()
------------------------------------------------------------------------
[2012-02-03 20:45:09] jonathan at scriptwriterthingy dot com
"This sounds like strtr() to me"
According to the php docs strstr says it "Returns part of haystack string from
the first occurrence of needle to the end of haystack." - it doesn't say
anything about replacing characters which is the main difference between my
request and the current strpbrk() function.
My request does have some similarities to str_replace() as mentioned above but
would do so strings instead of arrays.
------------------------------------------------------------------------
[2012-02-03 20:28:06] [email protected]
This sounds like strtr() to me
------------------------------------------------------------------------
[2012-02-03 20:21:05] jonathan at scriptwriterthingy dot com
Description:
------------
---
>From manual page: http://www.php.net/function.strpbrk
---
This is a great function I wasn't aware of until recently. I love that it can
find any character from a list of characters - very useful for filtering data.
Would be even better if there were a similar function that replaced any matched
character listed in the input string with:
1) a single specified character,
2) a character from a list/string of characters (similar to what you do with
str_replace but without the need for arrays)
3) a random character from the supplied list of characters mentioned in item 2.
#1 on that list is the most important of my request. #2 and 3 would be nice to
have but I can live without as str_replace already does some of this but
requires arrays.
Test script:
---------------
Partial demo of concept
$char_list = "-!@#$%^&*()+=-/?.>,<;:"; //characters we want to remove
$input_string = "Some data that's not supposed to have $puncuation!";
$replace_string = '';
$result_string = strpbrk_replace($input_string, $char_list, $replace_string);
Expected result:
----------------
And hopefully the result string looks like this:
"Some data that's not supposed to have puncuation"
Or if $replace_string had = ' ';
"Some data that's not supposed to have puncuation "
Actual result:
--------------
See above...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60974&edit=1