Is there a function in php to replace text with a variable but have it mainting the case of the text being replaced? For example,
$input1 = some word
Then I want to go out and find all occurances of "some other word" and "Some Other Word" and replace them with input1, but maintain their original case so they would become "some word" and "Some Word". Hopefully, my explaination makes sense. Is there an easy way to do this?
Thanks in advance for any help. I just started teaching myself php on the side about 2 weeks ago, so I don't even know what to look for.
replacing text with uper and lower case
Moderator: General Moderators
-
someguyhere
- Forum Contributor
- Posts: 181
- Joined: Sun Jul 27, 2008 3:24 pm
Re: replacing text with uper and lower case
I don't think there's an 'easy' way to do it. There certainly isn't a function to do it. I imagine your options are:
1. generate all the possible variations and then loop through them all.. bit of a hassle though, and awfully slow.
2. find all the positions of the needle words, then replace them more intelligently than str_replace can manage.
3. possibly use a regular expression. Not sure if that's possible though.
1. generate all the possible variations and then loop through them all.. bit of a hassle though, and awfully slow.
2. find all the positions of the needle words, then replace them more intelligently than str_replace can manage.
3. possibly use a regular expression. Not sure if that's possible though.
-
WebbieDave
- Forum Contributor
- Posts: 213
- Joined: Sun Jul 15, 2007 7:07 am
Re: replacing text with uper and lower case
If you needed to replace "History of the World" with "past events", which words would be capitalized, if any?
Either way, you could try one of the regex functions that have a callback.
http://us.php.net/manual/en/function.pr ... llback.php
Either way, you could try one of the regex functions that have a callback.
http://us.php.net/manual/en/function.pr ... llback.php