I'm auto-linking profiles existing on my site in blogpost texts which contain the profile names. To do so I...
1) ...extract currently ~500 rows (only?) from 4 different MySQL tables - containing different types of profiles - in a single database using 4 individual queries.
2) ...str_replace() every profile name individually with a link in the blogpost text, if that profile name exists (tried putting them in search-replace arrays before and do a single str_replace() as well).
While it does what it is supposed to do, it slows down the Blogpost overview page significantly. Loading 10 Posts on the overview page, in which each content is checked against the occurence of profile names, takes 30+ seconds to load. Without this whole autolink procedure the Blogpost overview page loads quickly.
I believe the culprit is step 2). What can I do to speed up the process of finding and replacing a large number of strings (coming from a database) within a single text string?