-
Thanks Daniel!
One more thing - why do you have to use a for loop when it says here that it takes arrays for both the first and second parameters?
-
-
It's simpler.
I like storing the items as keys and values so that they're next to each other (see my last post). If you store them in separate arrays, you could use your method, just with str_replace(), actually.
If you want to use my method and skip the loop, you'd have to do this (which would work fine):
$text = str_replace(array_keys($replacements),array_values($replacements),$text);
Note that in terms of processing time, it's probably about the same as the loop (because in reality the loop will happen anyway, within str_replace() because you're using arrays). It's slightly shorter and arguably 'simpler' code, but I think it's also a little harder because knowing those functions requires more familiarity with PHP-- so do whatever works for you. Personally if I'm at all unsure I prefer to use my own loops so I know exactly what's going on and I don't need to look up details for functions.
Daniel -
Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
Bookmarks