Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Image keyboard shortcut replacement thingymies

  1. #11
    Join Date
    Mar 2011
    Posts
    2,145
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    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?

  2. #12
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •