例如:
$stringA = 'Whatcha talkin bout Willis?';
$stringB = 'aeiou';
我需要将 stringB 中的所有字符与 stringA 中的任何匹配的字符都用<span>
.
我怎样才能做到这一点?
echo tagVowels($stringA);
function tagVowels($string) {
// ????
// So far I've been using a manual loop through each character.
// I'm hoping for a simpler/cleaner way.
for ($i = 0; $i <= strlen($string) -1; $i++) {
if (strpos()) {
$string = str_replace();
}
}
}
结果:
Wh<span>a</span>tch<span>a</span> t<span>a</span>lk<span>i</span>n bout W<span>i</span>ll<span>i</span>s