Help; .map to call array and .replace issue (auto tag text to url)

Help; .map to call array and .replace issue (auto tag text to url)

The title says it, i got an issue here while im using map of array to replace text to url.

1. The First question is, if the array has same text one of them have a space,
e.g.

  1. <head>
  2. <script>
  3. $(document).ready(function () {
          var p = $("div .post-body");
  4.       var arr = ["Bandai Entertainment", "Bandai", "etc... up to 50 or more maybe];
  5.       $.map(arr, function (e) {
                return p.html(p.html().replace(e,
                      '<a href="/search/?q='+e+'">'+e+'</a>'))
          });
  6. });
  7. </script></head>
  8. <body>
  9. <div class='post-body'>
  10. Producers: Bandai Entertainment, Bandai, More, Etc,<br />
  11. Genres: Horror, School</div></body>
the result will error like this

  1. <a href="/search/?q=<a href=" search="" ?q="Bandai&quot;">Bandai</a> Entertainment">Bandai EntertainmentL,
But when i switch the arr position like ["Bandai","Bandai Entertainment"] it will show Bandai only with url. the 'Entertainment' on the page is not linked to url.

2. Second question, i have too many array to replace text to url and it take some time to load the page. is there any option to make it faster in script position? or script place?
or like
1. find the text,
2. load array once,
3. if there any text equal one of the 'loaded array', replace it without loading again while?
i mean one time load array for page before replace-script running.

3. Maybe there's more question i will ask, for now i need help for the two first..

thanks.